File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Spring and the fly likes JSP Exception Handling in Same Page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "JSP Exception Handling in Same Page" Watch "JSP Exception Handling in Same Page" New topic
Author

JSP Exception Handling in Same Page

Victor M. Pereira
Ranch Hand

Joined: Mar 02, 2012
Posts: 50
I don't know if it's possible but I would like to handle exceptions in the same page of the form to avoid creating new pages just for exception handling.

For example I have business method: findByLastVisit(Date date);

That returns data or throws an exception if no data is found. On my jsp I have:


I would like to display those exceptions in the same place as errorInForm. How can I do this? Do I have to modify the web.xml to add the same page for exceptions?


regards,
Victor M. Pereira
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60800
    
  65

An exception means something has gone really really wrong. You should not be using exceptions for business errors such as form validation failures.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Victor M. Pereira
Ranch Hand

Joined: Mar 02, 2012
Posts: 50
Well is not really for form validation, I couldn't think of a better way of automatized messages.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60800
    
  65

Exceptions shouldn't be used for messaging. That's like using nuclear weapons to crack walnuts. Exceptions are for horrible conditions like null pointer exceptions and illegal states.

It looks as if you are using Spring. Why aren't you using Spring's messaging?
Victor M. Pereira
Ranch Hand

Joined: Mar 02, 2012
Posts: 50
You mean the resourcebundle of spring or by JMS?
Ken Rimple
author
Ranch Hand

Joined: Jul 20, 2010
Posts: 63

My quick answer - AJAXIZE the form post, and review the result. Come up with a JSON equivalent of an error list and convert it when received in your backend. There are probably built-in resources here for some of this. Roo includes a thin Spring Javascript livrary that wraps dojo and can convert form posts to ajax, but so does native Dojo and jQuery, etc.

So it could be (psuedo code here):



Ken Rimple
ken.rimple@gmail.com
Co-author, Manning Spring Roo in Action
I teach for Chariot Solutions (Spring, Maven, Hibernate, other courses). Schedule here
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60800
    
  65

Ken Rimple wrote:My quick answer - AJAXIZE the form post, and review the result. Come up with a JSON equivalent of an error list and convert it when received in your backend.

Great minds think alike. This is exactly what I do. I didn't know if Spring had something built in -- I use native jQuery with the Forms and Validation plugins.

The best part is that, in the case of errors, no context is lost that needs to be painstakingly re-created when using a traditional full-page form post.
 
 
subject: JSP Exception Handling in Same Page
 
Similar Threads
Using checkbox on Spring 2.5 MVC ?
Display values in jsp using json
design problem
problem with submit: NullValueInNestedPathException:
pagination exception in spring