File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Other Application Frameworks and the fly likes Error messsages in Spring MVC. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Other Application Frameworks
Bookmark "Error messsages in Spring MVC." Watch "Error messsages in Spring MVC." New topic
Author

Error messsages in Spring MVC.

pawan chopra
Ranch Hand

Joined: Jan 23, 2008
Posts: 408

Hi All,

I have a jsp page where user selectes a file for download , the request goes to spring Controller where I am doing some file handling, in case FileNotFound exception occurs I want to show a error message on the same jsp page from where the request has been made. I have tried Spring reference but it explains about errors which are related to form bean and bind to fields. I don't have any form bean I want to show controller errors on JSP page. Can any one please help me on this? Thanks in advance!

Regards,
Pawan Chopra.


Pawan Chopra
SCJP - DuMmIeS mInD
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

I think the easiest way is through configuration.

Adding a SimpleMappingExceptionResolver does the trick




I like that above the best.

or you can do it another way that is in the documentation here;

http://static.springframework.org/spring/docs/2.5.x/reference/mvc.html#mvc-exceptionhandlers

You implement the interface and inside the method you check to see if the Exception passed is that exception and then return the ModelAndView where the view string is the view that is the error page you wanted to display.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Hong Anderson
Ranch Hand

Joined: Jul 05, 2005
Posts: 1936
Mark, I'm afraid that is not what pawan wants, pawan wants to display error message in the same page.

I suggest to use Validator interface, you will implement a Validator, and inject to the controller.
http://static.springframework.org/spring/docs/2.0.x/reference/validation.html.


SCJA 1.0, SCJP 1.4, SCWCD 1.4, SCBCD 1.3, SCJP 5.0, SCEA 5, SCBCD 5; OCUP - Fundamental, Intermediate and Advanced; IBM Certified Solution Designer - OOAD, vUML 2; SpringSource Certified Spring Professional
pawan chopra
Ranch Hand

Joined: Jan 23, 2008
Posts: 408

Kengkaj Sathianpantarit wrote:
I suggest to use Validator interface, you will implement a Validator, and inject to the controller.
http://static.springframework.org/spring/docs/2.0.x/reference/validation.html.


You are right I am looking for this thing only thanks!

I got following while searching for this.

http://www.salixalba.uklinux.net/willow/computing/spring.html

The <spring:hasBindErrors> tag is used to access all of the errors on the form, including those which are not tied to specific fields.


Following is the code which I need to use in JSP:



But In my case I am implementing Validator interface in controller only. I do not have any commandBean for controller. the above code is using a commandBean, so can I use this in my controller?
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

Kengkaj Sathianpantarit wrote:Mark, I'm afraid that is not what pawan wants, pawan wants to display error message in the same page.

I suggest to use Validator interface, you will implement a Validator, and inject to the controller.
http://static.springframework.org/spring/docs/2.0.x/reference/validation.html.


Ah, I just saw the Exception, so assumed it was just about exception handling and sending them to an error page, not a validation.

Thanks

Mark
Hong Anderson
Ranch Hand

Joined: Jul 05, 2005
Posts: 1936
pawan, the easiest way is using SimpleFormController, and create a command class like the following:

Then in the validator you can check filePath property of FileBean object.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Error messsages in Spring MVC.
 
Similar Threads
please help me to solve following spring issues
SimpleFormController. HTML action left blank. Spring creates action under WEB-INF
Configure success view to be the same form view
I need help with this situation regarding form post parameters
IllegalStateException:Neither BindingResult nor plain target object for bean name available