You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by "Kumar, Sumit" <Su...@sogeti-usa.com> on 2003/12/18 23:15:07 UTC

Illegal State Exception while redirecting

Hello,

I am including a jsp header in every jsp page as follows:

<jsp:include page="ConnInclude_Authenticate.jsp" flush="true" />

In this header, I call a class that checks if the valid user objects exists
in session. Otherwise the class returns authentication as false. If the user
object donot exist I redirect to another web site using
response.sendRedirect. 

However I get illegal state Exception (java.lang.IllegalStateException
	at
org.apache.coyote.tomcat4.CoyoteResponseFacade.sendRedirect(CoyoteResponseFa
cade.java:340) 

Any suggestions please.. 

 The page of header is as follows:

<%
   boolean isAuthenticated =
AuthenticationManager.authenticate(request.getParameter("userId")==null?"":r
equest.getParameter("userId"),
 
request.getParameter("password")==null?"":request.getParameter("password"),s
ession);	
   if(!isAuthenticated)
   {	
	   System.out.println("\n AUTHENTICATION FAILED");

	
response.sendRedirect("http://sgtwebdv/gm?format=Sogeti/testAuth/portalHead.
shtml&appId=1&ul=/reports.jsp");
	   return;
   }
%> 

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


Re: Illegal State Exception while redirecting

Posted by Bill Barker <wb...@wilshire.com>.
The spec forbids an included page from changing the headers or the status
code (Section 8.3 of the 2.3 Servlet Spec, which is what TC 4.1 follows).
This means that it is illegal to call sendRedirect from an included page
(and doubly so from one with flush="true" :).

"Kumar, Sumit" <Su...@sogeti-usa.com> wrote in message
news:C167BFEA79682F43B5271DA351EB71BF46A2D6@SOGEX01...
> Hello,
>
> I am including a jsp header in every jsp page as follows:
>
> <jsp:include page="ConnInclude_Authenticate.jsp" flush="true" />
>
> In this header, I call a class that checks if the valid user objects
exists
> in session. Otherwise the class returns authentication as false. If the
user
> object donot exist I redirect to another web site using
> response.sendRedirect.
>
> However I get illegal state Exception (java.lang.IllegalStateException
> at
>
org.apache.coyote.tomcat4.CoyoteResponseFacade.sendRedirect(CoyoteResponseFa
> cade.java:340)
>
> Any suggestions please..
>
>  The page of header is as follows:
>
> <%
>    boolean isAuthenticated =
>
AuthenticationManager.authenticate(request.getParameter("userId")==null?"":r
> equest.getParameter("userId"),
>
>
request.getParameter("password")==null?"":request.getParameter("password"),s
> ession);
>    if(!isAuthenticated)
>    {
>    System.out.println("\n AUTHENTICATION FAILED");
>
>
>
response.sendRedirect("http://sgtwebdv/gm?format=Sogeti/testAuth/portalHead.
> shtml&appId=1&ul=/reports.jsp");
>    return;
>    }
> %>




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