• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Junilu Lacar
  • Martin Vashko
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Scott Selikoff
  • salvin francis
  • Piet Souris

Error messsages in Spring MVC.

 
Ranch Hand
Posts: 419
Mac jQuery Objective C
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
ranger
Posts: 17344
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 1936
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
pawan chopra
Ranch Hand
Posts: 419
Mac jQuery Objective C
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 17344
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 1936
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Story like this gets better after being told a few times. Or maybe it's just a tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!