File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes How to set 'If-Modified-Since ' header Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "How to set Watch "How to set New topic
Author

How to set 'If-Modified-Since ' header

Mohan Panigrahi
Ranch Hand

Joined: Sep 28, 2001
Posts: 142
Hi,
Can any one suggest how to set 'If-Modified-Since' header in the GET request. For that matter how do we set any header at all in the get request?
Thanks
Shawn Bayern
Author
Ranch Hand

Joined: May 06, 2002
Posts: 160
Originally posted by Mohan Panigrahi:
Hi,
Can any one suggest how to set 'If-Modified-Since' header in the GET request. For that matter how do we set any header at all in the get request?
Thanks

Setting headers in any HTTP request is up to the browser, not to the server. Your job as a JSP page author is to respond to the request. (As a technical answer, a Servlet 2.3 filter may wrap a request and alter any header or parameter it sees fit. But a JSP page has little need of this; modifying requests is generally part of a larger architecture that transcends the JSP page itself. For instance, you might modify requests in order to ensure proper authentication.)


Shawn Bayern<br />"JSTL in Action" <a href="http://www.jstlbook.com" target="_blank" rel="nofollow">http://www.jstlbook.com</a>
Mohan Panigrahi
Ranch Hand

Joined: Sep 28, 2001
Posts: 142
Hi Shawn ,
Thanks for the reply.
To clarify my question : I learned that the browser sends 'If-Modified-Since' header along with a request for a jsp page ( or any page what so ever)the server would first check if that page etc. has been modified since the time as specified in the 'If-Modified-Since' sent by the browser. If it has not been modified then the server would not send the entire page, but would just send the information that 'No, the page has not been modified'. On receiving this information the browser would display the page from its cache.
NOW, my question is : Let's say that I want to submit request for jsp page with a parameter ( name ) when some link is clicked. So I would do :
"<a href="http://hostName/webAppPath/Abc.jsp?name=Hari>Click Here</a>" Now I want to incorporate the setting of header If-Modified-Since in this link request. How would I do that?
Thanks
Shawn Bayern
Author
Ranch Hand

Joined: May 06, 2002
Posts: 160
Originally posted by Mohan Panigrahi:

NOW, my question is : Let's say that I want to submit request for jsp page with a parameter ( name ) when some link is clicked. So I would do :
"<a href="http://hostName/webAppPath/Abc.jsp?name=Hari>Click Here</a>" Now I want to incorporate the setting of header If-Modified-Since in this link request. How would I do that?

You can't easily do that; the header is entirely up to the browser. It's something of an abstraction violation to attempt it.
If you need something like this, it's probably best to set up a servlet that acts as a high-level proxy, retrieving the file using java.net.URL, through which you may set headers; then, the servlet can return whatever it receives to the browser. But the HTML <a> element doesn't give you the option of modifying HTTP headers.
Mohan Panigrahi
Ranch Hand

Joined: Sep 28, 2001
Posts: 142
Thanks Shawn,
It answers my question perfectly!
Shawn Bayern
Author
Ranch Hand

Joined: May 06, 2002
Posts: 160
Originally posted by Mohan Panigrahi:
Thanks Shawn,
It answers my question perfectly!

Cool! Another option, just in case you're interested, is to write a filter that converts a specific request-parameter (that is, from the query string) into a header for a wrapped ServletRequest object. This way, you get to avoid "proxying" -- having to retrieve and then return some HTML -- but the solution is a little trickier to write. Just figured I'd mention it in case it sparks an idea.
Sandep Chaturvedi
Ranch Hand

Joined: Aug 20, 2002
Posts: 49
Why would you ever want to do it yourself. If a response is not modified, I wouldn't like to set the flag and vice-versa and it can introduce unpredictability of result.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to set 'If-Modified-Since ' header