• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Setting response headers conditionally

 
Patil Niteen
Ranch Hand
Posts: 48
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ranchers ,

I need to set the response headers to prevent caching of the data. I am using the following code in a filter:



This code works fine.
Now, my requirement is to set the headers conditionally like:



But the headers are not being set in this case. Any way through which I can make it work?

Thanks and regards,
Nitin.
 
Paul Clapham
Sheriff
Pie
Posts: 20735
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The obvious thing would be to assign true to that "condition" variable. If the headers aren't being generated then you aren't doing that.
 
Patil Niteen
Ranch Hand
Posts: 48
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The scenario is :

When the user logs out , I am setting the session variable to null. If the user tries to view the previously visited page using the internet explorer's Back button, In a filter I am checking


if(session==null). If session is null , I am setting the header variables.


But , the header variables are not being set in this case.

Is the response commited before checking the condition?

Thanks and regards,
Nitin.
 
Paul Clapham
Sheriff
Pie
Posts: 20735
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Patil Niteen wrote:Is the response commited before checking the condition?


That's impossible to say. It's your code which is checking that condition, so perhaps your code might be committing the response before that. We can't see any of your code.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13055
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When the user logs out , I am setting the session variable to null.


What exactly do you think that accomplishes?

The API provides the invalidate() method in javax.servlet.http.HttpSession - thats what you should be using.

What are you using to monitor the values of the response headers?

Bill
 
Patil Niteen
Ranch Hand
Posts: 48
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am setting the attribute of the session for logout to null. I am checking the same session variable in the filter for valid login. If the attribute is null, I am trying to prevent caching of the page. This way , I am trying to prevent the user to view the visited pages after logout using Internet Explorer's BACK button.

The conditionally setting of the response headers is not working for me.

Here,s the code: For logout:


I am checking the userLogger attribute of the session in the filter as:



If the condition is removed from the code. The response headers are set and the user is prevented to view the visited pages after logout.
Also, the print statement prints: Response Committed:false.

Note: I am using this in a GRAILS application. Since, the issue is with the response and setting the headers , I have posted it here.
Thanks and regards,
Nitin
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13055
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If this was my problem I would use Firefox with live http headers turned on as the client to see what is actually being sent in the response headers.

That code you posted - in what method of the filter does it appear?

Bill
 
Patil Niteen
Ranch Hand
Posts: 48
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The filter code is:




Also, I tried this in after method and it doesn't work.
Thanks.
Nitin.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic