用Spring MVC 提交表单信息为什么报400的错误

具体情况如下,我有一个实体类user已声明getset方法,而且表单里面的name写的也和实体类的成员变量一样,在controller里面的参数是User user,当我提交的时候页面
出现400错误。
网上查了好久,我也测试了,用requestMapping(value="user" ,required=false)测试了,这样就包的500错误,后来有改为requestMapping(value="user" required=true)这次又包400错误了,
求助啊!谢谢各位大神!!

requestMapping用于匹配请求路径的,你确定有required参数?
要从request中提取参数,应该用requestParam吧!

这是controller的代码

import java.sql.Timestamp;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.SessionAttributes;
import com.tarena.dao.AccountDao;
import com.tarena.dao.ServiceDao;
import com.tarena.entity.Account;
import com.tarena.entity.page.AccountPage;

@Controller
@RequestMapping("/account")
@SessionAttributes("accountPage")
public class AccountController extends BaseController {

@Resource
private AccountDao accountDao;

@Resource
private ServiceDao serviceDao;

@RequestMapping("/findAccount.do")
public String find(AccountPage page, Model model) {
    page.setRows(accountDao.findRows(page));
    model.addAttribute("accountPage", page);

    List<Account> list = accountDao.findByPage(page);
    model.addAttribute("accounts", list);

    return "account/account_list";
}

@RequestMapping("/startAccount.do")
public String updateStart(@RequestParam("account_id") int id) {
    //暂停账务账号
    Account a = new Account();
    a.setAccount_id(id);
    a.setStatus("0");
    accountDao.updateStatus(a);
    return "redirect:findAccount.do";
}

@RequestMapping("/pauseAccount.do")
public String updatePause(@RequestParam("account_id") int id) {
    //暂停账务账号
    Account a = new Account();
    a.setAccount_id(id);
    a.setStatus("1");
    accountDao.updateStatus(a);

    //暂停其下属的业务账号
    serviceDao.pauseByAccount(id);

    return "redirect:findAccount.do";
}

@RequestMapping("/deleteAccount.do")
public String updateDelete(@RequestParam("account_id") int id) {
    //暂停账务账号
    Account a = new Account();
    a.setAccount_id(id);
    a.setStatus("2");
    accountDao.updateStatus(a);

    //删除其下属的业务账号
    serviceDao.deleteByAccount(id);

    return "redirect:findAccount.do";
}

@RequestMapping("/toUpdateAccount.do")
public String toUpdate(@RequestParam("account_id") int id, Model model) {
    Account a = accountDao.findById(id);
    model.addAttribute("account", a);
    return "account/update_account";
}

@RequestMapping("/updateAccount.do")
public String update(Account account) {
    accountDao.update(account);
    return "redirect:findAccount.do";
}

@RequestMapping("/toAddAccount.do")
public String toAdd() {
    return "account/add_account";
}

@RequestMapping("/addAccount.do")
public String add(Account account) {
    account.setStatus("0");
    account.setCreate_date(
        new Timestamp(System.currentTimeMillis()));
    accountDao.save(account);
    return "redirect:findAccount.do";
}

@RequestMapping("/searchAccount.do")
@ResponseBody
public Account searchAccount(String idcardNo) {
    return accountDao.findByIdcardNo(idcardNo);

}

}
这是JSP页面<%@ page pageEncoding="UTF-8" isELIgnored="false"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">



达内-NetCTOSS


<br> //保存结果的提示<br> function showResult() {<br> showResultDiv(true);<br> window.setTimeout(&quot;showResultDiv(false);&quot;, 3000);<br> }<br> function showResultDiv(flag) {<br> var divResult = document.getElementById(&quot;save_result_info&quot;);<br> if (flag)<br> divResult.style.display = &quot;block&quot;;<br> else<br> divResult.style.display = &quot;none&quot;;<br> }</p> <pre><code> //切换资费类型 function feeTypeChange(type) { var inputArray = document.getElementById(&quot;main&quot;).getElementsByTagName(&quot;input&quot;); if (type == 1) { inputArray[4].readOnly = true; inputArray[4].value = &quot;&quot;; inputArray[4].className += &quot; readonly&quot;; inputArray[5].readOnly = false; inputArray[5].className = &quot;width100&quot;; inputArray[6].readOnly = true; inputArray[6].className += &quot; readonly&quot;; inputArray[6].value = &quot;&quot;; } else if (type == 2) { inputArray[4].readOnly = false; inputArray[4].className = &quot;width100&quot;; inputArray[5].readOnly = false; inputArray[5].className = &quot;width100&quot;; inputArray[6].readOnly = false; inputArray[6].className = &quot;width100&quot;; } else if (type == 3) { inputArray[4].readOnly = true; inputArray[4].value = &quot;&quot;; inputArray[4].className += &quot; readonly&quot;; inputArray[5].readOnly = true; inputArray[5].value = &quot;&quot;; inputArray[5].className += &quot; readonly&quot;; inputArray[6].readOnly = false; inputArray[6].className = &quot;width100&quot;; } } &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;!--Logo区域开始--&gt; &lt;div id=&quot;header&quot;&gt; &lt;img src=&quot;../images/logo.png&quot; alt=&quot;logo&quot; class=&quot;left&quot;/&gt; &lt;a href=&quot;#&quot;&gt;[退出]&lt;/a&gt; &lt;/div&gt; &lt;!--Logo区域结束--&gt; &lt;!--导航区域开始--&gt; &lt;div id=&quot;navi&quot;&gt; &lt;ul id=&quot;menu&quot;&gt; &lt;li&gt;&lt;a href=&quot;../index.html&quot; class=&quot;index_off&quot;&gt;&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href=&quot;../role/role_list.html&quot; class=&quot;role_off&quot;&gt;&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href=&quot;../admin/admin_list.html&quot; class=&quot;admin_off&quot;&gt;&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href=&quot;../fee/fee_list.html&quot; class=&quot;fee_on&quot;&gt;&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href=&quot;../account/account_list.html&quot; class=&quot;account_off&quot;&gt;&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href=&quot;../service/service_list.html&quot; class=&quot;service_off&quot;&gt;&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href=&quot;../bill/bill_list.html&quot; class=&quot;bill_off&quot;&gt;&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href=&quot;../report/report_list.html&quot; class=&quot;report_off&quot;&gt;&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href=&quot;../user/user_info.html&quot; class=&quot;information_off&quot;&gt;&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href=&quot;../user/user_modi_pwd.html&quot; class=&quot;password_off&quot;&gt;&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; &lt;!--导航区域结束--&gt; &lt;!--主要区域开始--&gt; &lt;div id=&quot;main&quot;&gt; &lt;div id=&quot;save_result_info&quot; class=&quot;save_fail&quot;&gt;保存失败,资费名称重复!&lt;/div&gt; &lt;form action=&quot;addCost.do&quot; method=&quot;post&quot; class=&quot;main_form&quot;&gt; &lt;div class=&quot;text_info clearfix&quot;&gt;&lt;span&gt;资费名称:&lt;/span&gt;&lt;/div&gt; &lt;div class=&quot;input_info&quot;&gt; &lt;input type=&quot;text&quot; name=&quot;name&quot; class=&quot;width300&quot; value=&quot;&quot;/&gt; &lt;span class=&quot;required&quot;&gt;*&lt;/span&gt; &lt;div class=&quot;validate_msg_short&quot;&gt;50长度的字母、数字、汉字和下划线的组合&lt;/div&gt; &lt;/div&gt; &lt;div class=&quot;text_info clearfix&quot;&gt;&lt;span&gt;资费类型:&lt;/span&gt;&lt;/div&gt; &lt;div class=&quot;input_info fee_type&quot;&gt; &lt;input type=&quot;radio&quot; name=&quot;costType&quot; id=&quot;monthly&quot; onclick=&quot;feeTypeChange(1);&quot; /&gt; &lt;label for=&quot;monthly&quot;&gt;包月&lt;/label&gt; &lt;input type=&quot;radio&quot; name=&quot;costType&quot; checked=&quot;checked&quot; id=&quot;package&quot; onclick=&quot;feeTypeChange(2);&quot; /&gt; &lt;label for=&quot;package&quot;&gt;套餐&lt;/label&gt; &lt;input type=&quot;radio&quot; name=&quot;costType&quot; id=&quot;timeBased&quot; onclick=&quot;feeTypeChange(3);&quot; /&gt; &lt;label for=&quot;timeBased&quot;&gt;计时&lt;/label&gt; &lt;/div&gt; &lt;div class=&quot;text_info clearfix&quot;&gt;&lt;span&gt;基本时长:&lt;/span&gt;&lt;/div&gt; &lt;div class=&quot;input_info&quot;&gt; &lt;input type=&quot;text&quot; name=&quot;base_duration&quot; value=&quot;&quot; class=&quot;width100&quot; /&gt; &lt;span class=&quot;info&quot;&gt;小时&lt;/span&gt; &lt;span class=&quot;required&quot;&gt;*&lt;/span&gt; &lt;div class=&quot;validate_msg_long&quot;&gt;1-600之间的整数&lt;/div&gt; &lt;/div&gt; &lt;div class=&quot;text_info clearfix&quot;&gt;&lt;span&gt;基本费用:&lt;/span&gt;&lt;/div&gt; &lt;div class=&quot;input_info&quot;&gt; &lt;input type=&quot;text&quot; name=&quot;base_cost&quot; value=&quot;&quot; class=&quot;width100&quot; /&gt; &lt;span class=&quot;info&quot;&gt;元&lt;/span&gt; &lt;span class=&quot;required&quot;&gt;*&lt;/span&gt; &lt;div class=&quot;validate_msg_long error_msg&quot;&gt;0-99999.99之间的数值&lt;/div&gt; &lt;/div&gt; &lt;div class=&quot;text_info clearfix&quot;&gt;&lt;span&gt;单位费用:&lt;/span&gt;&lt;/div&gt; &lt;div class=&quot;input_info&quot;&gt; &lt;input type=&quot;text&quot; name=&quot;unit_cost&quot; value=&quot;&quot; class=&quot;width100&quot; /&gt; &lt;span class=&quot;info&quot;&gt;元/小时&lt;/span&gt; &lt;span class=&quot;required&quot;&gt;*&lt;/span&gt; &lt;div class=&quot;validate_msg_long error_msg&quot;&gt;0-99999.99之间的数值&lt;/div&gt; &lt;/div&gt; &lt;div class=&quot;text_info clearfix&quot;&gt;&lt;span&gt;资费说明:&lt;/span&gt;&lt;/div&gt; &lt;div class=&quot;input_info_high&quot;&gt; &lt;textarea class=&quot;width300 height70&quot; name=&quot;descr&quot;&gt;&lt;/textarea&gt; &lt;div class=&quot;validate_msg_short error_msg&quot;&gt;100长度的字母、数字、汉字和下划线的组合&lt;/div&gt; &lt;/div&gt; &lt;div class=&quot;button_info clearfix&quot;&gt; &lt;input type=&quot;submit&quot; value=&quot;保存&quot; class=&quot;btn_save&quot; /&gt; &lt;input type=&quot;button&quot; value=&quot;取消&quot; class=&quot;btn_save&quot; onclick=&quot;history.back();&quot; /&gt; &lt;/div&gt; &lt;/form&gt; &lt;/body&gt; </code></pre> <p></html><br> 这是实体类account<br> package com.tarena.entity;</p> <p>import java.sql.Date;<br> import java.sql.Timestamp;</p> <p>public class Account {<br> private Integer account_id;<br> private Integer recommender_id;<br> private String login_name;<br> private String login_passwd;<br> private String status;<br> private Timestamp create_date;<br> private Timestamp pause_date;<br> private Timestamp close_date;<br> private String real_name;<br> private String idcard_no;<br> private Date birthdate;<br> private String gender;<br> private String occupation;<br> private String telephone;<br> private String email;<br> private String mailaddress;<br> private String zipcode;<br> private String qq;<br> private Timestamp last_login_time;<br> private String last_login_ip;<br> public Integer getAccount_id() {<br> return account_id;<br> }<br> public void setAccount_id(Integer accountId) {<br> account_id = accountId;<br> }<br> public Integer getRecommender_id() {<br> return recommender_id;<br> }<br> public void setRecommender_id(Integer recommenderId) {<br> recommender_id = recommenderId;<br> }<br> public String getLogin_name() {<br> return login_name;<br> }<br> public void setLogin_name(String loginName) {<br> login_name = loginName;<br> }<br> public String getLogin_passwd() {<br> return login_passwd;<br> }<br> public void setLogin_passwd(String loginPasswd) {<br> login_passwd = loginPasswd;<br> }<br> public String getStatus() {<br> return status;<br> }<br> public void setStatus(String status) {<br> this.status = status;<br> }<br> public Timestamp getCreate_date() {<br> return create_date;<br> }<br> public void setCreate_date(Timestamp createDate) {<br> create_date = createDate;<br> }<br> public Timestamp getPause_date() {<br> return pause_date;<br> }<br> public void setPause_date(Timestamp pauseDate) {<br> pause_date = pauseDate;<br> }<br> public Timestamp getClose_date() {<br> return close_date;<br> }<br> public void setClose_date(Timestamp closeDate) {<br> close_date = closeDate;<br> }<br> public String getReal_name() {<br> return real_name;<br> }<br> public void setReal_name(String realName) {<br> real_name = realName;<br> }<br> public String getIdcard_no() {<br> return idcard_no;<br> }<br> public void setIdcard_no(String idcardNo) {<br> idcard_no = idcardNo;<br> }<br> public Date getBirthdate() {<br> return birthdate;<br> }<br> public void setBirthdate(Date birthdate) {<br> this.birthdate = birthdate;<br> }<br> public String getGender() {<br> return gender;<br> }<br> public void setGender(String gender) {<br> this.gender = gender;<br> }<br> public String getOccupation() {<br> return occupation;<br> }<br> public void setOccupation(String occupation) {<br> this.occupation = occupation;<br> }<br> public String getTelephone() {<br> return telephone;<br> }<br> public void setTelephone(String telephone) {<br> this.telephone = telephone;<br> }<br> public String getEmail() {<br> return email;<br> }<br> public void setEmail(String email) {<br> this.email = email;<br> }<br> public String getMailaddress() {<br> return mailaddress;<br> }<br> public void setMailaddress(String mailaddress) {<br> this.mailaddress = mailaddress;<br> }<br> public String getZipcode() {<br> return zipcode;<br> }<br> public void setZipcode(String zipcode) {<br> this.zipcode = zipcode;<br> }<br> public String getQq() {<br> return qq;<br> }<br> public void setQq(String qq) {<br> this.qq = qq;<br> }<br> public Timestamp getLast_login_time() {<br> return last_login_time;<br> }<br> public void setLast_login_time(Timestamp lastLoginTime) {<br> last_login_time = lastLoginTime;<br> }<br> public String getLast_login_ip() {<br> return last_login_ip;<br> }<br> public void setLast_login_ip(String lastLoginIp) {<br> last_login_ip = lastLoginIp;<br> }</p> <p>}</p>