File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes how to prevent caching? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "how to prevent caching?" Watch "how to prevent caching?" New topic
Author

how to prevent caching?

kriti sharma
Ranch Hand

Joined: Feb 16, 2001
Posts: 160
i am designing a web-app in which i need to call servlet on a hyperlink. the problem is that whenever i click on the hyperlink for second or higher times it shows results of the the first click. i had put <http-equiv="Pragma" content="no-cache"> after the <html> tag but to no avail. please help me so that each time the link is clicked the servlet is called afresh.
arnel nicolas
Ranch Hand

Joined: Dec 16, 2003
Posts: 149
In your web.xml under the WEB-INF directory of your application.Try to add this:

<init-param>
<param-name>nocache</param-name>
<param-value>true</param-value>
</init-param>

arnel
kriti sharma
Ranch Hand

Joined: Feb 16, 2001
Posts: 160
hey guys, is it that no one knew the answer or that it was too easy a thing to be answered.anyways i got the answer.


response.setHeader("Cache-Control","no-cache");
response.setHeader("Pragma","no-cache");

its working now
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
neither is guaranteed to work, especially with proxy servers.
The approach using init-params makes sure the application server itself doesn't cache anything, the approach using HTTP headers ASKS browsers and proxies not to cache (but not all will honour such requests).


42
kriti sharma
Ranch Hand

Joined: Feb 16, 2001
Posts: 160
i cud not understand the init param idea given above, i though it was a joke. can someone explain to me why would container read and interpret the init param. init-param element is solely for the use of the programmer.
Rahul Juneja
Ranch Hand

Joined: Aug 03, 2002
Posts: 425
Hi All,

I think this is what guys are talking abt related to Proxy Server Caching. We can Stop Proxy Server from Caching by the following Statement.



Thanks,
Rahul Juneja
rahul.juneja@patni.com
Only Emails from Corporate email Ids are received on this email,others are filtered as of rediff or yahoo


Rahul Juneja
ThoughtClicks - http://techlabs.thoughtclicks.com
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
yes, that will get MOST proxies to not cache, but there is no guarantee.
I've once encountered a proxy that would cache anything we sent it no matter what we told it not to cache.
In the end we got the network admins to set up an exlusion rule for our server (it was our own proxy ) so all requests to it would be ignored by the proxy.

Could have been a configuration error, but doesn't bode well.
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
I saw a thread on another site where someone got so desperate to stop caching that they appended incrementing parameters on the URL just so it would never match a previous request. That's gotta work, doesn't it?


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Rahul Juneja
Ranch Hand

Joined: Aug 03, 2002
Posts: 425
Stan,

Thats surely gonna work but don't u think its totally Illogical to have such solution.

Thanks,
Rahul Juneja
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to prevent caching?
 
Similar Threads
global veriable + hyper link
Multiple Frames Updated by One Servlet?
'A HREF = a row in Database' for each req_id in Servlets
HTML and Servlets
Passing parameters to the servlet