我的代码有问题,请帮帮我,我有这样的错误 既不是BindingResult也不是bean名称的明确目标对象'命令'可用作请求属性
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 :(得分: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">
答案 1 :(得分:0)
感谢您的宝贵建议我将其更改为modelattribute但现在也显示此错误org.apache.jasper.JasperException:在第15行处理JSP页面/jsp/registration.jsp时发生异常
java.lang.IllegalStateException:BindingResult和bean名称的简单目标对象&#39; aaa&#39;可用作请求属性
HTTP Status 500 - An exception occurred processing JSP page /jsp/registration.jsp at line 15
输入例外报告
message在第15行处理JSP页面/jsp/registration.jsp时发生异常
说明服务器遇到内部错误,导致无法完成此请求。
例外
org.apache.jasper.JasperException:在第15行处理JSP页面/jsp/registration.jsp时发生异常
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>