wood burning stoves
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
JavaRanch » Java Forums » Java » JSF
Bookmark "java.lang.IllegalStateException " Watch "java.lang.IllegalStateException " New topic


Bhosiz Pol

Joined: Sep 03, 2012
Posts: 1

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;
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();


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

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

@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: 17410

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.

An IDE is no substitute for an Intelligent Developer.
I agree. Here's the link: http://aspose.com/file-tools
subject: java.lang.IllegalStateException
It's not a secret anymore!