• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to set 'If-Modified-Since ' header

 
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Author
Posts: 160
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.)
 
Mohan Panigrahi
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 160
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 142
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Shawn,
It answers my question perfectly!
 
Shawn Bayern
Author
Posts: 160
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic