Announcement Announcement Module
No announcement yet.
How to pass errors back to a view -numpty question Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to pass errors back to a view -numpty question

    I have a fileUpload view which is all working fine. However, if I attempt to upload a file that exceeds the maxfilesizelimit I get an exception which I can trap with a HandlerExceptionResolver, I'm ok with that. However, where I'm stuck is how do I pass control back to the fileUpload view with the appropriate error message.?

    eg in my ExceptionResolver I have..

    public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
    if(ex instanceof MaxUploadSizeExceededException){
    return new ModelAndView("fileUpload");

    return null;

    This just gives me ..
    2005-02-11 16:02:28,736 ERROR [org.springframework.web.servlet.DispatcherServlet] - <Could not complete request>
    javax.servlet.ServletException: Neither Errors instance nor plain target object for bean name fileRequest available as request attribute

  • #2
    This is from the petclinic example. This response is sent to the user when no matchig last name is found. Refer petclinic for details.

    		if &#40;results.size&#40;&#41; < 1&#41; &#123;
    			// no owners found
    			errors.rejectValue&#40;"lastName", "notFound", null, "not found"&#41;;
    			return showForm&#40;request, response, errors&#41;;


    • #3
      Thanks, but the code you refer to is in the formcontroller itself. I need to get back to the form from the exceptionhandler


      • #4
        I have a similar problem!!

        I have a similar problem - I have an interceptor for login and I want to display an appropriate message on the login page - but how do you add an error to the view from here?

        I suppose I could redirect the user to another controller but that seems a bit daft.

        Any ideas?



        • #5
          one solution

          I've gone back to using struts. There is so little documentation/support on this stuff. I've got tired of spending half a day or more trying to work out how to do something I already know how to do in Struts.