Announcement Announcement Module
No announcement yet.
Could not find Errors instance Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Could not find Errors instance

    javax.servlet.ServletException: Could not find Errors instance for bean 'report' in request: add the Errors model to your ModelAndView via errors.getModel()
    org.apache.jasper.runtime.PageContextImpl.doHandle PageException(
    org.apache.jasper.runtime.PageContextImpl.handlePa geException(
    org.apache.jsp.WEB_002dINF.views.report_jsp._jspSe rvice(

    How can I fix this? I'm trying to create a basic MVC app with the SimpleFormController following the MVC-step-by-step documents. I've searched all over the Net and on these boards and I've found nothing that works.

    * Created on January 30, 2005, 7:10 PM

    package com.spacepirates.ispreport;

    import org.springframework.web.servlet.mvc.SimpleFormCont roller;
    import org.springframework.web.servlet.ModelAndView;
    import org.springframework.web.servlet.view.RedirectView;

    import org.springframework.validation.BindException;

    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;

    import java.util.Map;
    import java.util.HashMap;

    import org.apache.commons.logging.Log;
    import org.apache.commons.logging.LogFactory;

    import java.text.SimpleDateFormat;
    * @author scott
    public class ReportFormController extends SimpleFormController {

    /** Logger for this class and subclasses */
    protected final Log logger = LogFactory.getLog(getClass());

    private ReportManager reportManager;
    private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd @ HH:mm:ss z");

    public ModelAndView onSubmit(Object command, BindException errors)
    throws Exception {

    String now = (new java.util.Date()).toString();

    Map myModel = new HashMap();

    myModel.put("now", now);
    myModel.put("reports", getReportManager().getReports());

    return new ModelAndView(new RedirectView(getSuccessView()),errors.getModel());

    protected Object formBackingObject(HttpServletRequest request) throws ServletException {

    Report theReport = new Report();
    // set properties to some defaults... could be done in the Report class I suppose.
    theReport.setIsp("China Telecom");

    java.util.Date now = new java.util.Date();


    return theReport;


    public ReportManager getReportManager() {
    return reportManager;

    public void setReportManager(ReportManager reportManager) {
    this.reportManager = reportManager;


  • #2
    This won't work using a RedirectView.

    The RedirectView appends the model as query parameters to the newly generated request URL it redirects to, an Errors object will be toString'ed and appended to the URL, it's not an object anymore when arriving in the JSP redirected to...



    • #3
      thanks for the tip, what to do now?

      Is there any documentation for the MVC feature other than the 2003 MVC-step-by-step (which is obsolete)?

      Where can I see an example of the use of SimpleFormController?

      return new ModelAndView(getSuccessView());
      return new ModelAndView(getSuccessView(),errors.getModel());

      Doesn't work either.

      javax.servlet.ServletException: Neither Errors instance nor plain target object for bean name report available as request attribute
      org.apache.jasper.runtime.PageContextImpl.doHandle PageException(
      org.apache.jasper.runtime.PageContextImpl.handlePa geException(

      One working example is what I need.


      • #4
        Re: thanks for the tip, what to do now?

        Originally posted by ShanghaiScott
        Is there any documentation for the MVC feature other than the 2003 MVC-step-by-step (which is obsolete)?
        The ref docs are online at, other than that there's the JavaDoc for the relevant classes and the sample applications included in the distributions.



        • #5
          Could you post your context configuring the form controller?


          • #6

            <!-- Validator and Form Controller for the "Report" page -->
            <bean id="reportValidator" class="com.spacepirates.ispreport.ReportValidator"/
            <bean id="reportForm" class="com.spacepirates.ispreport.ReportFormContro ller">
            <property name="sessionForm"><value>true</value></property>
            <property name="commandName"><value>Report</value></property>
            <property name="commandClass"><value>com.spacepirates.isprep ort.Report</valu
            <property name="validator"><ref bean="reportValidator"/></property>
            <property name="formView"><value>report</value></property>
            <property name="successView"><value>reports.htm</value></property>
            <property name="reportManager">
            <ref bean="reports"/>

            The idea here was: replace the PriceIncrease class in the MVC step-by-step example, with my Report class...


            • #7
              Don't use:
              Map myModel = new HashMap();

              Instead use:
              Map myModel = errors.getModel();

              Then add properties to myModel, and return modelAndView:
              return new ModelAndView(getSuccessView(),myModel);

              Hope that helps,


              • #8
                tried that already

                As part of "programming by trial and error" which this shit forces me to do, I tried Map myModel = errors.getModel() and so on. Doesn't work either.

                I also tried something based on the jpetstore AccountFormController's onSubmit, but that doesn't work either.

                I really wish the example from MVC step-by-step actually worked. I would be done with my tiny project 2 days ago.

                Clearly I am doing something wrong! But without a working example, it's pretty hard to figure this out. Is the MVC step-by-step example really wrong? Why can't I just replace the PriceIncrease class with my Report class?

                Should I be using SpringFramework 1.1.x? Do most people still use 1.0?


                • #9
                  Are you still getting this error?

                  Should I be using SpringFramework 1.1.x? Do most people still use 1.0?
                  Why not look at the samples which are included in the distribution, and so are always up-to-date with the current release.