jsp页面如下:
<form id="myForm" method="get" action="/mvc/student/getList">
<tr>
<td>学号:</td>
<td><input id="studentId" name="studentId" value="${student.studentId}" /></td>
<td>姓名:</td>
<td><input id="name" name="name" value="${student.name}" /></td>
<td>性别:</td>
<td>男<input type="radio" name="sex" value="1" ${student.sex == 1 ?"checked=checked":""}/>
女<input type="radio" name="sex" value="0" ${student.sex == 0 ?"checked=checked":""}/></td>
<td>
<input type="button" value="查询" οnclick="validate()" />
<input type="reset" value="重置"/>
</td>
<td><input type="button" value="添加" /></td>
</tr>
</form>
三个输入项中,至少可以输入一项就可以提交。当不填写第一个项:学号,提交表单后,地址栏显示:
http://localhost:8080/mvc/student/getList?studentId=&name=hisky&sex=1,页面提示出错信息如下:
HTTP ERROR 400
Problem accessing /mvc/student/getList. Reason:
BAD_REQUEST
问题已解决!
studentId在java中定义为int类型,页面不填写此项,传递的参数为null,spring不能做null和int对应的转换。将int的属性改为Integer可解决。