Hei,
I am trying to get a command object in a class which extends a MultiActionController. The Controller class is:
public class RaspunsNouController extends MultiActionController
{
public ModelAndView submit(HttpServletRequest request,HttpServletResponse response,Response obj) throws Exception
{
System.out.println("Submit method called");
System.out.println(request.getParameter("username"));
Response obiectR = (Response) obj;
System.out.println(obiectR.getClass());
System.out.println(obiectR.getAgence_response());
System.out.println(obiectR.getResponse());
return new ModelAndView("raspunsNou");
}
}
the important part of the jsp file is:
<form:form method="POST" commandName="response" style="position:relative; top:50px; left:100px; width:400px; border:2px red solid;" >
<form:textarea path="response" />
<br/><br/>
<button type="button" onclick="location.href='submit.htm'">Valider</button>
<button type="button">Annuler</button>
</form:form>
And the error I am getting is :
org.apache.jasper.JasperException: java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'response' available as request attribute org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:532) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:450) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:391) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334) javax.servlet.http.HttpServlet.service(HttpServlet.java:722) org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:238) org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:250) org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1047) org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:817) org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719) org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644) org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:549) javax.servlet.http.HttpServlet.service(HttpServlet.java:621) javax.servlet.http.HttpServlet.service(HttpServlet.java:722) root cause java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'response' available as request attribute org.springframework.web.servlet.support.BindStatus.(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.AbstractDataBoundFormElementTag.getName(AbstractDataBoundFormElementTag.java:160) org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.autogenerateId(AbstractDataBoundFormElementTag.java:147) org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.resolveId(AbstractDataBoundFormElementTag.java:138) org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.writeDefaultAttributes(AbstractDataBoundFormElementTag.java:122) org.springframework.web.servlet.tags.form.AbstractHtmlElementTag.writeDefaultAttributes(AbstractHtmlElementTag.java:408) org.springframework.web.servlet.tags.form.TextareaTag.writeTagContent(TextareaTag.java:95) org.springframework.web.servlet.tags.form.AbstractFormTag.doStartTagInternal(AbstractFormTag.java:102) org.springframework.web.servlet.tags.RequestContextAwareTag.doStartTag(RequestContextAwareTag.java:79) org.apache.jsp.WEB_002dINF.jsp.raspunsNou_jsp._jspx_meth_form_005ftextarea_005f0(raspunsNou_jsp.java:221) org.apache.jsp.WEB_002dINF.jsp.raspunsNou_jsp._jspx_meth_form_005fform_005f0(raspunsNou_jsp.java:140) org.apache.jsp.WEB_002dINF.jsp.raspunsNou_jsp._jspService(raspunsNou_jsp.java:80) org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) javax.servlet.http.HttpServlet.service(HttpServlet.java:722) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:417) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:391) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334) javax.servlet.http.HttpServlet.service(HttpServlet.java:722) org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:238) org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:250) org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1047) org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:817) org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719) org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644) org.springfra开发者_StackOverflow中文版mework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:549) javax.servlet.http.HttpServlet.service(HttpServlet.java:621) javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
I realise that I should do some binding somewhere (like in simpleFormController , in the formBackingObject method, but I don't know how or where).
You need to put a Object with name "response" in you model. Because your form expect it:
<form:form method="POST" commandName="response"
Response obiectR = (Response) obj;
ModelMap model = new ModelMap();
model.addAttribute("response", obiectR);
return new ModelAndView("raspunsNou", model);
Form Spring Reference:
The preceding JSP (
<form method="POST">...
) assumes that the variable name of the form backing object is 'command'. If you have put the form backing object into the model under another name (definitely a best practice), then you can bind the form to the named variable like so:<form:form commandName="user">
So what you need to do is: put the command object with the name used in the jsp ("response") in the Model and return it via ModelAndView. You have to do it in all command method, that uses THE jsp to render.
It seams that you are using Spring 2.x, may you should have look at the SimpleFormController.
精彩评论