Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

SHowing the Exception back to the JSP from DAO Layer  RSS feed

 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From the UI , i am clickiing a function that will actually call this method inside the DAO Layer . Now please tell me how can i get access to this exception under my JSP to show to the User , if this exception comes



 
Dieter Quickfend
Bartender
Posts: 543
4
Java Netbeans IDE Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can throw it (or some other, homecooked RuntimeException) to the Servlet and put it in your session/request. You can also bubble it up and throw an exception in your servlet that will redirect you to the assigned error jsp, and you can access the exception object from there.

Not a good idea to show too much exception information to the end user, though. Personally, I'd just put an exception message label with an empty request attribute in your jsp, and if the exception occurs, redirect to the same jsp and set a descriptive String to the request attribute. But that's just me.
 
Pene charl
Greenhorn
Posts: 21
Hibernate Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The best way to show error messages for end user,just make string object and return from the DAO layer function to jsp
And the jsp has to produce your own textual based message to end user.
This is easy and best option for web related projects instead of exception.
 
Jans Daniels
Greenhorn
Posts: 3
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I personally dislike the idea of showing too much error information to the user, because most users won't be interested in a stacktrace (well...except maybe hack3rz).
But on the other hand, as a developer I would like to see the whole stacktrace quick without digging into some logfiles on the server.
So in order to hide details, you could throw up the exception, define a error-page in your web.xml
and in your error.jsp comment out the stacktrace by putting something like this (uses JSTL):
So you just have to view the webpages sourcecode to see the full stacktrace, and the 'normal' user won't be confused by too much information

HTH
Jans
 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!