---- Original Message -----
From: "A R Krishna" <[EMAIL PROTECTED]>
> Can any one help me in fixing the exception. This particular exception
is written every time i acess this particular servlet.
>
> I am checking for entries in database. If entries are < 0 then the
redirection to another servlet takes place. If entries are >0 then the
message will be printed on browser using printwriter statemebts.
>
> I have read in some documentation saying after "sendRedirect" method
call the processing of that particular servlet will stop. But here i am
facing this problem
>
> [Tue Jul 03 16:08:41 PDT 2001] Exception raised in servlet:
mlsb.RenameSite
> [Tue Jul 03 16:08:41 PDT 2001] java.io.IOException: Attempt to write to
the output stream after calling HttpServletResponse's sendRedirect method
[snipped]
The problem is exactly what the exception is telling you. The servlet is
trying to write to the output stream after sendRedirect has been called.
Now as for the documentation saying "after "sendRedirect" method call the
processing of that particular servlet will stop", I think what the
documentation was trying to convey was that no more response should be sent
after a redirect has been done. The servlet is a java program. So a call to
a method sendRedirect() can not stop the execution of doGet() (provided no
Exceptions are raised). The doGet method will continue to execute beyond the
point sendRedirect() is called.
public void doGet(HttpServletRequest req, HttpServletResponse res)
{
OutputStream out = res.getOutputStream();
// some processing..
if(someCondition)
{
sendRedirect("/redirect/path");
}
System.out.println(" I continue executing after the sendRedirect");
// the following line will result in an exception being raised...
// if redirect has been done
out.write("Do not write if redirect is done".getBytes());
}
In the above code fragment, even if redirect takes place you will see the
println being executed and then an exception will be raised when u try to
write to the OutputStream. You should write a return statement after the
sendRedirect method to halt the further execution of doGet Method. That
should solve your problem.
Regds,
Gokul
>
> Regards
> RK
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html