File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes Illegal State exception response.sendRedirect Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » JSP
Bookmark "Illegal State exception response.sendRedirect" Watch "Illegal State exception response.sendRedirect" New topic
Author

Illegal State exception response.sendRedirect

Avneet Singh
Ranch Hand

Joined: Apr 25, 2006
Posts: 51
Hi

On some of my jsp pages response.sendRedirect throws an illegal State Exception.

Basically i validate user session on each page , when i ge a null value i have to redirect the user to error page , but on some pages it doesnt work.
eg.

String logId = (String)session.getAttribute("login");
Vector oData = (Vector)session.getAttribute("Data");
if((logId == null) || (oData == null)){
response.sendRedirect("error.jsp?errCode=31");
}

This code works on some pages and on one or two pages it gives illegal state exception.

Thanks
Avneet
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Check whether you have committed the response in those pages before doing sendRedirect(). Because this will result in IllegalStateException.
Avneet Singh
Ranch Hand

Joined: Apr 25, 2006
Posts: 51
On these pages the very first thing it does is check for session and redirect if it doesnt exist. even though jsp forward works in these scenarios. But i dont prefer it .

response object is not commited before this code.

and structure of all pages are same check for session and redirect if not found. It works in most of them .
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12791
    
    5
Redirect is done using headers so if the response headers are already sent you get illegal state exception. I bet there is some path by which the output is flushed, you just have not found it yet.
Bill
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Illegal State exception response.sendRedirect