You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Anand Prasad <ax...@hotmail.com> on 2000/10/13 01:39:59 UTC
Exception thrown when Forwarding
Hi
I store a session variable and basically check in every page whether that
varibale contains any value.
When the user directly wants to enter the url without logging, I would like
to redirect him to login page.
Here is code snippet.
//
<% if((String)session.getValue("loginId")==null){ %>
<jsp:forward page="/login.htm" />
<% } %>
It throws up an exception in apache and tomcat.
I think I am making very stupid mistake...but unable to figure it.
Any suggestions, Thanks
javax.servlet.ServletException: Cannot forward as OutputStream or Writer has
already been obtained
at java.lang.Throwable.fillInStackTrace(Native Method)
at java.lang.Throwable.fillInStackTrace(Compiled Code)
at java.lang.Throwable.(Compiled Code)
at java.lang.Exception.(Compiled Code)
at javax.servlet.ServletException.(ServletException.java:161)
at
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:386)
at
dv._0002fdv_0002fsecurity_0002ejspsecurity_jsp_2._jspService(_0002fdv_0002fsecurity_0002ejspsecurity_jsp_2.java:92)
at
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:126)
at javax.servlet.http.HttpServlet.service(Compiled Code)
at
org.apache.jasper.runtime.JspServlet$JspServletWrapper.service(JspServlet.java:174)
at org.apache.jasper.runtime.JspServlet.serviceJspFile(Compiled
Code)
at org.apache.jasper.runtime.JspServlet.service(Compiled Code)
at javax.servlet.http.HttpServlet.service(Compiled Code)
at org.apache.tomcat.core.ServletWrapper.handleRequest(Compiled
Code)
at
org.apache.tomcat.core.RequestDispatcherImpl.include(RequestDispatcherImpl.java:262)
at org.apache.jasper.runtime.PageContextImpl.include(Compiled Code)
_________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.
Share information about yourself, create your own public profile at
http://profiles.msn.com.
Re: Exception thrown when Forwarding
Posted by Steve Weiss <sw...@aamc.org>.
Anand Prasad wrote:
>
> Hi
>
> I store a session variable and basically check in every page whether that
> varibale contains any value.
>
> When the user directly wants to enter the url without logging, I would like
> to redirect him to login page.
>
> Here is code snippet.
> //
> <% if((String)session.getValue("loginId")==null){ %>
> <jsp:forward page="/login.htm" />
> <% } %>
>
My guess would be trying to cast to a String. There's no point in doing
this if you're checking for null. Just do:
if ( session.getAttribute("loginId") == null ) {
..
Also, session.getValue() is deprecated, you should use
session.getAttribute() instead.
-S
--
Steve Weiss Association of American Medical Colleges
(202)828-0428 mailto:sweiss@aamc.org http://www.aamc.org
Re: Exception thrown when Forwarding
Posted by Christopher Farley <ch...@northernbrewer.com>.
On Thu, 12 Oct 2000, Anand Prasad wrote:
> When the user directly wants to enter the url without logging, I would like
> to redirect him to login page.
>
> Here is code snippet.
> //
> <% if((String)session.getValue("loginId")==null){ %>
> <jsp:forward page="/login.htm" />
> <% } %>
>
> It throws up an exception in apache and tomcat.
It is impossible to redirect to a different page if the output buffer has
been flushed (sent to the HTTP server). If your conditional doesn't appear
until you've written a lot of output, you could try increasing the size of
your output buffer, for example: <%@ page buffer="12kb" %>
Re: [tomcat-users] Exception thrown when Forwarding
Posted by kenneth topp <ca...@prodigy.net>.
Anand,
Make it the very top line of your jsp. If you've already sent some print
lines, it's too late. you can examine the compiled to java version of
your jsp to see that there is output above the redirect attempt.
Alternativly, you can do this via interceptor/servlet and avoid this
mess...
I don't know any rational for behavior (it's in the spec though). It
seems like simply a performance requirment that many users would happily
turn off. Did that surprise anyone ;)
Kenneth Topp
---
to unsubscribe: tomcat-user-unsubscribe@jakarta.apache.org
for more info: http://jakarta.apache.org/getinvolved/mail.html
On Thu, 12 Oct 2000, Anand Prasad wrote:
> Hi
>
> I store a session variable and basically check in every page whether that
> varibale contains any value.
>
> When the user directly wants to enter the url without logging, I would like
> to redirect him to login page.
>
> Here is code snippet.
> //
> <% if((String)session.getValue("loginId")==null){ %>
> <jsp:forward page="/login.htm" />
> <% } %>
>
> It throws up an exception in apache and tomcat.
>
> I think I am making very stupid mistake...but unable to figure it.
>
> Any suggestions, Thanks
>
> javax.servlet.ServletException: Cannot forward as OutputStream or Writer has
> already been obtained
> at java.lang.Throwable.fillInStackTrace(Native Method)
> at java.lang.Throwable.fillInStackTrace(Compiled Code)
> at java.lang.Throwable.(Compiled Code)
> at java.lang.Exception.(Compiled Code)
> at javax.servlet.ServletException.(ServletException.java:161)
> at
> org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:386)
> at
> dv._0002fdv_0002fsecurity_0002ejspsecurity_jsp_2._jspService(_0002fdv_0002fsecurity_0002ejspsecurity_jsp_2.java:92)
> at
> org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:126)
> at javax.servlet.http.HttpServlet.service(Compiled Code)
> at
> org.apache.jasper.runtime.JspServlet$JspServletWrapper.service(JspServlet.java:174)
> at org.apache.jasper.runtime.JspServlet.serviceJspFile(Compiled
> Code)
> at org.apache.jasper.runtime.JspServlet.service(Compiled Code)
> at javax.servlet.http.HttpServlet.service(Compiled Code)
> at org.apache.tomcat.core.ServletWrapper.handleRequest(Compiled
> Code)
> at
> org.apache.tomcat.core.RequestDispatcherImpl.include(RequestDispatcherImpl.java:262)
> at org.apache.jasper.runtime.PageContextImpl.include(Compiled Code)
> _________________________________________________________________________
> Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.
>
> Share information about yourself, create your own public profile at
> http://profiles.msn.com.
>