Stupid error work with actionRequest.getParameter("something")

My jsp page:

<portlet:actionURL name="addPerson" var="addPersonURL">
</portlet:actionURL>


<form action="<%= addPersonURL %>" method="post">
<table>
<tr>
<td>ID</td>
<td><input type="text" name="<portlet:namespace/>id" id="id" /></td>
</tr>
<tr>
<td>First Name</td>
<td><input type="text" name="<portlet:namespace/>firstName" id="firstName" /></td>
</tr>
<tr>
<td>Last Name</td>
<td><input type="text" name="<portlet:namespace/>lastName" id="lastName" /></td>
</tr>
<tr>
<td>Birthday</td>
<td><input type="text" name="<portlet:namespace/>birthDate" id="birthDate" /></td>
</tr>
<tr>
<td><input type="submit" value="submit" /></td>
</tr>
</table>
</form>


My controller class:

public void addPerson(ActionRequest actionRequest, ActionResponse actionResponse)
throws IOException, PortletException, SQLException {
String id = actionRequest.getParameter("id");
String firstName = actionRequest.getParameter("firstName");
String lastName = actionRequest.getParameter("lastName");
String birthDate = actionRequest.getParameter("birthDate");
log.info("birthDate: " + birthDate +"--"+id +"==" + firstName +"***" + lastName);
Person person = new Person(Integer.parseInt(id), firstName, lastName, new Date(birthDate));
pm.insertPerson(person);
}

Previously, in my controller's method, I can't get value of birthdate. The thing is I change the value of name like this:

<input type="text" name="<portlet:namespace/>Birth Date" id="birthDate" />

actionRequest.getParameter("param"), the param always needs to match "name" attribute in input element rather than id attribute. Be aware of that. 

你可能感兴趣的:(Stupid error work with actionRequest.getParameter("something"))