---
title: "Exception：jsp提交form时input不填任何值，出现400错误"
author: "hiskyrisa"
date: "2013-03-23T16:45:09Z"
tags: []
categories: ["Web前端"]
slug: "exception-jsp-form-input-400"
draft: false
lastmod: "2013-03-23T22:10:12Z"
id: 1835451
url: "https://201109061007.iteye.com/blog/1835451"
---

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="查询" onclick="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://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可解决。

另一种解决办法，参考：[http://blog.csdn.net/goldenfish1919/article/details/7039104](http://blog.csdn.net/goldenfish1919/article/details/7039104)