tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Antony Paul" <antonypau...@hotmail.com>
Subject Re: Use of return statement in servlet.
Date Fri, 31 Oct 2003 10:07:00 GMT
Thaks for the extra information.

I am using response.sendRedirect(). That is why I want to get out of the
servlet and go to the target page.

Antony


----- Original Message -----
From: "Rodrigo Ruiz" <rruiz@gridsystems.com>
To: "Tomcat Users List" <tomcat-user@jakarta.apache.org>
Sent: Friday, October 31, 2003 2:51 PM
Subject: Re: Use of return statement in servlet.


> Anthony, putting a return in a servlet code will not create any state
> problem for the servlet itself. You could have problems if you have
> opened resources that need finalization or closing before returning, for
> example DB connections, or opened streams others than the servlet input
> and ouput ones, but that depends on the code, and it is independent from
> the servlet engine.
>
> Of course, if you do not redirect to anywhere, or display nothing, what
> you will get in the browser is a neat clean blank page ;-)
>
> I am not sure at all, but I think JSPs could be different, depending on
> the compiler implementation. I think Jasper generated code does not have
> problems with return statements, but I check it with every new release I
> download, just in the case ;-)
>
> What I do is to create a simplest JSP:
>
> <!-- JSP beginning -->
> Hello World
> <!-- JSP end -->
>
> And compile it. Then, looking at the generated servlet code, I check
> that no resource-freeing operations are done after writing "Hello Worl"
> to the output stream. The moment this happens, the moment I will have a
> lot of problems :-P
>
> Hope it helps you,
> Rodrigo
>
>
> Antony Paul wrote:
>
> >Thanks for the reply
> >I want the browser to point to the query page if user did not provide
enough
> >data or an error happens like database connection is not available. I
want
> >user to re enter data or wait for some time .  So I dont want to use
> >"requestDispatcher.forward()"  method or redirect to an error page. I
want
> >to know is there any problems in using the return statement in
servlets/jsp.
> >
> >Antony Paul
> >
> >----- Original Message -----
> >From: "Nikola Milutinovic" <Nikola.Milutinovic@ev.co.yu>
> >To: "Tomcat Users List" <tomcat-user@jakarta.apache.org>
> >Sent: Friday, October 31, 2003 12:00 PM
> >Subject: Re: Use of return statement in servlet.
> >
> >
> >
> >
> >>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
> >>
> >>
> >>
> >>
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> >For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> >
> >
> >
> >
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
>

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