| Author |
java.lang.IllegalStateException
|
Bhosiz Pol
Greenhorn
Joined: Sep 03, 2012
Posts: 1
|
|
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
Joined: May 12, 2009
Posts: 218
|
|
> 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
Joined: Aug 09, 2012
Posts: 179
|
|
Hi,
@Bhosiz, please use code tags for your code
|
Programming is about thinking, NOT coding
|
 |
Vishal Shaw
Ranch Hand
Joined: Aug 09, 2012
Posts: 179
|
|
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
Joined: Jun 25, 2001
Posts: 14491
|
|
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.
|
Customer surveys are for companies who didn't pay proper attention to begin with.
|
 |
 |
|
|
subject: java.lang.IllegalStateException
|
|
|