Can anyone help me with my code? I have the following error message.
Here is the form in my JSP where the problem occurs.Code:HTTP Status 500 - -------------------------------------------------------------------------------- type Exception report message description The server encountered an internal error () that prevented it from fulfilling this request. exception org.apache.jasper.JasperException: java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'comment' available as request attribute org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:541) 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 'comment' 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:271) org.apache.jsp.GuestBook_jsp._jspx_meth_form_005fform_005f0(GuestBook_jsp.java:216) 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)
This is my controller class.Code:<form:form modelAttribute="comment" method="POST" action="/addComment"> <table> <tr> <td><form:label path="name">Name:</form:label></td> <td><form:input path="name" /></td> </tr> <tr> <td><form:label path="comment">Message:</form:label></td> <td><form:textarea path="comment" rows="10" cols="50" /></td> </tr> <tr> <td><input type="submit" value="Submit comment" /></td> <td> </td> </tr> </table> </form:form>
web.xmlCode:package com.controller; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.servlet.ModelAndView; import com.dao.CommentDAO; import com.model.Comment; @Controller public class CommentController { @ModelAttribute public Comment getComment() { return new Comment(); } @RequestMapping(value = "comment", method = RequestMethod.POST) public ModelAndView comment() { return new ModelAndView("comment", "command", new Comment()); } @RequestMapping(value = "/addComment", method = RequestMethod.POST) public String addComment(@ModelAttribute("comment") Comment comment, ModelMap model) { 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); model.addAttribute("comment", comment); if (commentDAO.writeComment(comment) == true) { return "GuestBook"; } return "Oops"; } }
ghs1986-servlet.xmlCode:<?xml version="1.0" encoding="UTF-8"?> <web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> <display-name>Granada High School Class of 1986</display-name> <servlet> <servlet-name>ghs1986</servlet-name> <servlet-class> org.springframework.web.servlet.DispatcherServlet </servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>ghs1986</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <listener> <listener-class>com.configuration.ConfigurationListener</listener-class> </listener> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <welcome-file-list> <welcome-file>home.jsp</welcome-file> </welcome-file-list> </web-app>
applicationContext.xmlCode:<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"> <mvc:annotation-driven /> <context:component-scan base-package="com.controller" /> <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="suffix" value=".jsp" /> </bean> </beans>
Code:<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> <beans> <bean id="comment" class="com.model.Comment" /> </beans>


Reply With Quote
