我工作的一个Spring MVC 3.1应用程序,我的JSP不上去。 我得到我的浏览器屏幕的下面。
org.apache.jasper.JasperException: An exception occurred processing JSP page /GuestBook.jsp at line 31
28: <form:form method="post" action="GuestBook.jsp">
29: <table>
30: <tr>
31: <td><form:label path="comment.name">Name</form:label></td>
32: <td><form:input path="comment.name" /></td>
33: </tr>
34: <tr>
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:524)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:429)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
root cause
java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'command' available as request attribute
org.springframework.web.servlet.support.BindStatus.<init>(BindStatus.java:141)
org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getBindStatus(AbstractDataBoundFormElementTag.java:174)
org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getPropertyPath(AbstractDataBoundFormElementTag.java:194)
org.springframework.web.servlet.tags.form.LabelTag.autogenerateFor(LabelTag.java:129)
org.springframework.web.servlet.tags.form.LabelTag.resolveFor(LabelTag.java:119)
org.springframework.web.servlet.tags.form.LabelTag.writeTagContent(LabelTag.java:89)
org.springframework.web.servlet.tags.form.AbstractFormTag.doStartTagInternal(AbstractFormTag.java:102)
org.springframework.web.servlet.tags.RequestContextAwareTag.doStartTag(RequestContextAwareTag.java:79)
org.apache.jsp.GuestBook_jsp._jspx_meth_form_005flabel_005f0(GuestBook_jsp.java:269)
org.apache.jsp.GuestBook_jsp._jspx_meth_form_005fform_005f0(GuestBook_jsp.java:214)
org.apache.jsp.GuestBook_jsp._jspService(GuestBook_jsp.java:127)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
下面是完整的形式。
<form:form method="post" action="GuestBook.jsp">
<table>
<tr>
<td><form:label path="comment.name">Name</form:label></td>
<td><form:input path="comment.name" /></td>
</tr>
<tr>
<td><form:label path="comment.message">Message</form:label></td>
<td><form:textarea path="comment.message" rows="10" cols="50" /></td>
</tr>
<tr>
<td><input type="submit" value="Submit comment" /></td>
<td> </td>
</tr>
</table>
</form:form>
这是我在我的控制器类。
@Controller
@RequestMapping("GuestBook")
public class CommentController {
@RequestMapping(value = "/GuestBook", method = RequestMethod.POST)
public String addComment(@ModelAttribute("comment") Comment comment, BindingResult result) {
CommentDAO commentDAO = new CommentDAO();
java.util.Date today = new java.util.Date();
java.sql.Date date = new java.sql.Date(today.getTime());
comment.setDate(date);
if (commentDAO.writeComment(comment) == true) {
return "redirect:GuestBook.jsp";
}
return "redirect:Oops.jsp";
}
@RequestMapping("/GuestBook")
public ModelAndView showComments() {
return new ModelAndView("comments", "command", new Comment());
}