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.)
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
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.
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.