• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Illegal State exception response.sendRedirect

 
Avneet Singh
Ranch Hand
Posts: 51
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2874
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check whether you have committed the response in those pages before doing sendRedirect(). Because this will result in IllegalStateException.
 
Avneet Singh
Ranch Hand
Posts: 51
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13048
6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic