• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java.lang.IllegalStateException

 
Bhosiz Pol
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Hi
i had a code to clear all the history of my browser. but it generates an error as "java.lang.IllegalStateException "

my code is:

Cookie[] cookies = request.getCookies();
Cookie opentoken = null;
for(Cookie c : cookies){
System.out.println("inside for");
if (session != null) {
opentoken = c;
opentoken.setMaxAge(0);
opentoken.setValue("");
response.addCookie(opentoken);
response.sendRedirect(request.getContextPath());
response.setHeader("Pragma", "no-cache");
response.setHeader("Cache-Control", "no-cache");
response.setHeader("Cache-Control", "no-store");
response.setHeader("Cache-Control", "must-revalidate");
response.setHeader("Expires", "Mon, 8 Aug 2006 10:00:00 GMT");
request.getSession( false ).invalidate();


break;
}
}


can anyone tell me how to solve it?
 
Brendan Healey
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

> i had a code to clear all the history of my browser

Now that would be a bit of a security nightmare wouldn't it. What is it you are trying to do exactly, do you want a
page or pages to not be cached in the browser cache? you seem to be sending a redirect before setting the response
headers.

Also you don't say where the exception is thrown, or the context in which this code is running, a servlet filter maybe?
 
Vishal Shaw
Ranch Hand
Posts: 179
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

@Bhosiz, please use code tags for your code
 
Vishal Shaw
Ranch Hand
Posts: 179
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator




I cut out a piece of code from your post.

As you can see the first line redirects your response. After that you are still working on the response object, so it is bound to throw the exception , like Brendan said.
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18108
52
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the JavaRanch, Bhosiz!

As a general rule, anything that requires intimate interaction with the HTTPServletResponse object should not be done in JSF code, it should be done in a plain old servlet.

JSF's architecture is very abstract, and it operates in a 2-dimensional mode that can conflict with attempts to treat the process a linear the way traditional servlets and JSPs do.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic