• 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
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

Error Message Display in Spring MVC

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First of all I want to start by saying that I am new to both Spring and Spring MVC.

Here is my question:

I am using Spring 3.0 for doing this.
Event: User clicks a link on my homepage.
Output: I have to show an error message saying "Service not available" on my homepage (in case an error is thrown by a controller).

Currently I just want to simulate this scenario without any business logic so I want to have a link on my homepage and when I click it, it should go to the controller which will always throw an exception. All I need to do is to catch this exception and show it on my Jsp page as "Service not available".

I have searched online but could not find a step by step tutorial to do this... Please guide me.
 
ranger
Posts: 17344
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Ted Trip wrote:First of all I want to start by saying that I am new to both Spring and Spring MVC.

Here is my question:

I am using Spring 3.0 for doing this.
Event: User clicks a link on my homepage.
Output: I have to show an error message saying "Service not available" on my homepage (in case an error is thrown by a controller).

Currently I just want to simulate this scenario without any business logic so I want to have a link on my homepage and when I click it, it should go to the controller which will always throw an exception. All I need to do is to catch this exception and show it on my Jsp page as "Service not available".

I have searched online but could not find a step by step tutorial to do this... Please guide me.



Well, are you using annotation, if so you can add this method to any one of your controllers



Mark
 
Ted Trip
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot for your reply Mark, however if I understand right this method is redirecting me to a new view.

I want the error message to be displayed on the same page from where the link was clicked. It is like a form validation but there is no form, just a link.
 
Mark Spritzler
ranger
Posts: 17344
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Ted Trip wrote:Thanks a lot for your reply Mark, however if I understand right this method is redirecting me to a new view.

I want the error message to be displayed on the same page from where the link was clicked. It is like a form validation but there is no form, just a link.



Ahh, didn't read into that one. ;)

method=exception handler method

Well you could have that method return the same string used to get to that URL. Or return null from that method. That will direct them back to the same page. If you truly want all the error messages, maybe you need to wrap that link in a Spring form tag so you can do validation and binding and have Spring automatically return an error object to display.

Unfortunately, I don't have an example to show and could only direct you to documentation to go further. I am more a middle tier guy.

Good Luck

Mark
 
That's a very big dog. I think I want to go home now and hug this 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!