2016-01-04 20 views
0

我对这个代码的问题,请帮助我,我有豆的名字“命令”可以作为请求属性这样 无论BindingResult一个错误也不是普通的目标对象Spring MVC中registraton一些程序错误

controllercode:

public class RegistrationController { 
@RequestMapping(value="/reg" ,method = RequestMethod.POST) 
public String reg(@ModelAttribute("aaa") User user,ModelMap model,BindingResult res){ 
    model.addAttribute("Fname",user.getFname()); 
    System.out.println(user.getFname()); 
    model.addAttribute("Lname", user.getLname()); 
    model.addAttribute("Email", user.getEmail()); 
    model.addAttribute("Pwd", user.getPwd()); 
    model.addAttribute("Phnum", user.getPhnum()); 
    return "NewFile"; 


    } 
} 

<form:form method="POST" action="/reg" name="aaa"> 
     <table> 
      <tr> 
       <td width="127"><form:label path="Fname">Employee Id:</form:label></td> 
       <td width="102"><form:input path="Fname" /></td> 
      </tr> 
      <tr> 
       <td width="127"><form:label path="Lname">Employee Id:</form:label></td> 
       <td width="102"><form:input path="Lname" /></td> 
      </tr> 
      <tr> 
       <td width="127"><form:label path="Email">Employee Id:</form:label></td> 
       <td width="102"><form:input path="Email" /></td> 
      </tr> 
      <tr> 
       <td width="127"><form:label path="Pwd">Employee Id:</form:label></td> 
       <td width="102"><form:input path="Pwd" /></td> 
      </tr> 
      <tr> 
       <td width="127"><form:label path="Phnum">Employee Id:</form:label></td> 
       <td width="102"><form:input path="Phnum" /></td> 
      </tr> 

     </table> 

回答

0

尝试改变

<form:form method="POST" action="/reg" name="aaa"> 

<form:form method="POST" action="/reg" commandName="aaa"> 

<form:form method="POST" action="/reg" modelAttribute="aaa"> 
0

感谢您的宝贵建议我改变,为的ModelAttribute,但现在它也显示此错误org.apache.jasper.JasperException:发生异常处理JSP页面/第15行的jsp/registration.jsp

java.lang.IllegalStateException:BindingResult和bean名称'aaa'的普通目标对象都不可用作为请求属性

HTTP Status 500 - An exception occurred processing JSP page /jsp/registration.jsp at line 15 

类型异常报告

消息的异常发生处理JSP页/jsp/registration.jsp在线路15

描述服务器遇到阻止其完成此请求一个内部错误。

例外

org.apache.jasper.JasperException:发生异常处理JSP页面/jsp/registration.jsp在15行

12: <form:form method="POST" action="/reg" modelAttribute="aaa"> 
13:    <table> 
14:     <tr> 
15:      <td width="127"><form:label path="Fname">Employee Id:</form:label></td> 
16:      <td width="102"><form:input path="Fname" /></td> 
17:     </tr> 
18:     <tr>