Originally posted by samart mateo: if i removed the exception, it will return error such as below:
It blows my mind as to what i should do exactly...huhu
Then i do not know.. but try this one ...let see
it may be the problem with your methods which are used by your servlet... so better put your code inside try then specify common Exception// but your mentioning only SQLException insteadof you put Exception
Joined: Feb 06, 2006
but your mentioning only SQLException insteadof you put Exception
This doesnt really matter, even if i code every single Exceptions to be thrown, it still give the same error. I think it should have something to do with missing some other declaration...
You can't let the servlet code launch exceptions that are not declared in the HttpServlet signs. In this case, the servlet must throw only ServletException and IOException, nothing else. If your code contains statements which can cause other types of exceptions, you must catch them and handle them in the proper way. Commonly, on exception like for example SQLException, what you have to do is to catch it, generate some sort of error message and redirect/forward to an error jsp which will display the error message (note that this way the doPost method is not throwing the root exception, is handling it). More generally, exceptions caused by your methods should be handled directly by your own code (error message generation, error logging or whatever you want), the servlet should throw ServletException or IOException only if something went wrong in the request/response process.
The proper way to deal with exceptions in a servlet:
You wrap the XyzException (which stands for any non-servlet exception) in a ServletException and throw it. This way, the original exception becomes the root cause of the servlet exception, and any error handling mechanisms established in the deployment descriptor take effect.
Originally posted by Matteo Di Furia: Commonly, on exception like for example SQLException, what you have to do is to catch it, generate some sort of error message and redirect/forward to an error jsp which will display the error message
It is much better to wrap the exception as I have shown in the previous reply and to let the error handlers declared in the deployment descriptor take effect. Handling the exceptions in servlet code is not recommended.