Rolland Crunk wrote:
>
> At 01:43 PM 2/19/99 +0000, Westaway Mike M wrote:
> >I'm running JSP 0.92 on sun sparc.
> >
> >any ideas why ?
> >
>
> Using the JavaWebServer or the servlet runner (sun.servlet.http.HttpServer), right?
> I too have encountered this problem as well, but have no explaination as to its
> cause.  It seems to occur more frequently with the servlet runner, and I haven't
> seen it happen if response.sendRedirect() is called from within a servlet (as
> opposed to a jsp).  I haven't encountered it with IBM WebSphere/Apache and
> haven't tried any of the other jsp engines.
>
> So in response to your question, no ideas why, but if you or anyone else solves
> this, please post to the list (as I will do if I stumble across the answer).
>
> rc
>

I too encountered the problem on several occasions. I am not sure this
is the real explanation of the problem, but here is what I have noticed.
When you use response.sendRedirect(), there shouldn't be any "write" or
"print" to the output stream (or writer), before or after this call. I
think that this call is not expecting anything to come with it because
you are specifying the address of the new page to fetch. Thus if you
write to the output stream, depending on the implementation, it will
notice that you are writing more than content length, because it is
supposed to be 0...

Thus when using sendRedirect(), you should be carefull and write
somenthing like:

service()
{
  // code that DO NOT write on output stream

  if(my_condition_is_true)
  {
     response.sendRedirect(..);
     return; // so that you are sure not to write something to the
output stream
  }
}

If you have a jsp page like that:
<HTML>
<BODY>
<%
  if(my_condition_is_true)
  {
    response.sendRedirect(...);
    return; // for the same reason!!!
  }
%>
</BODY>
</HTML>

Obviously this will raise the exception because <HTML><BODY> will be
sent to the output stream before the redirection... I agree that it is
not really easy to manage!

Hope this helps.

Yan

--

http://eowyn.fr.eu.org/~yan/ | [EMAIL PROTECTED]

SocialNet: Where people connect... http://www.socialnet.com

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JSP-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to