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
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.
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.
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