wood burning stoves 2.0*
The moose likes JSF and the fly likes java.lang.IllegalStateException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "java.lang.IllegalStateException " Watch "java.lang.IllegalStateException " New topic
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: 16019
    
  20

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java.lang.IllegalStateException