Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

redirect in a filter class

 
reubin haz
Ranch Hand
Posts: 287
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have j2ee web app that uses filter to determine the timeout period. If the current time is longer than the last access time for a certain length. it will redirects to a logout page. But I got error: java.lang.IllegalStateException: Cannot forward after response has been committed. I know this error would occur if there is already some output of the page. But this is from a filter class. It's mapped to /* and is called before accessing any page. Why it's still complain this error?
Thanks.

 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When done correctly, it should not throw any exceptions.

Instead of calling doFilter() you send a redirect to break the chain.

Could you send some code?
 
reubin haz
Ranch Hand
Posts: 287
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I found that the error only occurs if I redirect it to an external website page. If I just redirect to another page within my web app, it's fine. But I need redirect it to an external webpage....
 
reubin haz
Ranch Hand
Posts: 287
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I found a solution. I use that redirected internal page to redirect again to the external webpage. Then it's working.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic