• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JSP Exception Handling in Same Page

 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
An exception means something has gone really really wrong. You should not be using exceptions for business errors such as form validation failures.
 
Victor M. Pereira
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well is not really for form validation, I couldn't think of a better way of automatized messages.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You mean the resourcebundle of spring or by JMS?
 
author
Posts: 63
Mac OS X Spring Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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):

 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic