tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Nikola Milutinovic <Nikola.Milutino...@ev.co.yu>
Subject Re: Use of return statement in servlet.
Date Fri, 31 Oct 2003 06:30:15 GMT
Antony Paul wrote:
> Hi,
>   If any one feel it off topic mark it as off topic.
>   I want to exit from a servlet if no database connection is available. For
> this can I use a return statement in the beginning of a servlet. Will it
> cause any state problems. I dont like putting the code in an if block. There
> will be lots of if blocks.

A servlet is a web application component. It is invoked when a web client makes 
a request. The client expects SOMETHING as a response from the server and, thus, 
from the servlet.

So, quitting with no response is not a good practice. What you should do is 
display an error page. There are several ways you can do it, 
"requestDispatcher.forward()" or throw an exception and have custom error pages 
ready.

Nix.


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Mime
View raw message