??? Using JSPs to Send Not-Modified-Since Header ???

Hi all,
In looking at past posts, I'm afraid I know the horrible answer
to this issue but I thought I'd ask just in case I missed
anything.
Let me start by saying I'm using Tomcat v4.0.4 beta 3.
As you know, when a client (usually a web browser) has a cached
version of a resource (usually a web page) it can send an
"If-Modified-Since" header to the HTTP server. The server
compares the time/date stamp specified in the header with that of
the requested resource. If the resource has not been modified
since the time specified in the "If-Modified-Since" header, the
server sends back a 304 (Not-Modified) response, effectively
telling the client (usually a web browser) that its cached
version of the resource is still valid.
When writing a servlet, it's easy to handle this sort of
scenario. The javax.servlet.http.HttpServlet class has a
"service()" method. This method first checks if the incoming HTTP
method is a GET. If it is, the "service()" method proceeds to
call the "getLastModified()" method of the servlet. As a
developer, you can override "getLastModified()" to return a long
value representing the last time the requested resource was
changed. Depending on the value returned by "getLastModified()"
(note that -1 is returned if you don't override the method) the
"service()" method may simply return a 304, Not-Modified response
rather than calling the servlet's "doGet()" method.
Now, the $18.32 Question: How do you ensure "getLastModified()"
is called in JSP?
No, you cannot simply do this:
<%!
   public long getLastModified() {
      return xxx;
%>The problem is that the above method will never be called by the
container.
I traced through some of the Tomcat/Catalina/Jasper code and it
seems to me that the response code is being set to 200/OK very
early on in the processing.
I also took a cursory look at the JSP spec and didn't find any
indication of setting a "Not-Modified" response code...so, I am
thinking this is something that is (strangely) missing in the JSP
specification. I have a JSP page that needs to update itself once
per day. Therefore, it would be very handy to have the
"getLastModified()" functionality enjoyed by servlet writers.
Can anyone confirm this?
Thanks...

I've not come across this before, but like you I cannot find any mention of how to handle modification dates in the JSP spec. I can think of a couple of possible ways round this:
1. Try to delegate the functionality to a servlet. You'd need to pass the JSPs modification date and handle the return. Seems messy and I haven't tried it.
2. Add code to the JSP to read the headers directly and set the appropriate status code. e.g. at start of JSP:
<%@page  import="java.util.*" %>
<%
if (request.getMethod().equals("GET")) {
   GregorianCalendar lastModified = new GregorianCalendar(2002, 01, 01); // use constant for testing
   response.setDateHeader("Last-Modified", lastModified.getTimeInMillis());  //always set header
   long modifiedSince = -1;
   try {
      modifiedSince = request.getDateHeader("If-Modified-Since");
   } catch (IllegalArgumentException iae) {
        // System.out.println(iae);
   if (modifiedSince != -1 && modifiedSince > lastModified.getTimeInMillis()) {     
      response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
      return;
%>This would probably best be implemented as a custom tag if needed in more than one page.

Similar Messages

  • Safari seems not sending If-Modified-Since header for main address

    Not sure I'm in the appropriate forum but let's try (if there is more appropriate one please advise).
    When Safari requests a resource (page, image...) to a web server it doesn't provide If-Modified-Since header for the main resource of the request. That means the web server can't answer "resource not modified, use your cache". This is not the behavior of other browsers and not good in terms of performance for the web server as well as for the user.
    However Safari sends this If-Modified-Since for the sub-elements of the resource (e.g. images, css in a page...). Which is good.
    Is there a way to influence Safari's behavior to provide a If-Modified-Since for the main resource requested to the server?
    acama,

    Found out the answer.  IIS 6 does in fact steal "If-Modified-Since" and "If-None-Match" headers, but only on custom 404 redirects.  That's actually what I'm doing here (that'll teach me not to put details in a question when I think they're irrelevant -- actually I just forgot).
    Here's two discussions on the issue (they're using ASP, but apparently it's the same for ColdFusion):
    http://www.eggheadcafe.com/conversation.aspx?messageid=32839787&threadid=32839787
    http://www.webmasterworld.com/microsoft_asp_net/3935439.htm

  • If-modified-since header?

    Google tells me I need to be hosted on a server that supports this header (and it makes sense from a Google perspective). My host tells me that his servers do support that header. Yet when I test my pages on his server, the tool I am using tells me no support. Can anyone here help me with this?

    OK - for this to work, you need to insert a preamble on each PHP page -
    <?php
    $tsstring = gmdate('D, d M Y H:i:s ', $timestamp) . 'GMT';
    $etag = $language . $timestamp;
    $if_modified_since = isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) ? $_SERVER['HTTP_IF_MODIFIED_SINCE'] : false;
    $if_none_match = isset($_SERVER['HTTP_IF_NONE_MATCH']) ? $_SERVER['HTTP_IF_NONE_MATCH'] : false;
    if ((($if_none_match && $if_none_match == $etag) || (!$if_none_match)) &&
    ($if_modified_since && $if_modified_since == $tsstring))
    header('HTTP/1.1 304 Not Modified');
    exit();
    else
    header("Last-Modified: $tsstring");
    ?>
    This is from the discussion here -
    http://stackoverflow.com/questions/1971721/how-to-use-http-cache-headers-with-php
    which I had seen once, but it was not clear to me that this was to be used on the pages involved, and thought it might be a way to check the if-modified-since header from a PHP page instead of a way to make the page send the header.

  • Using the if-modified since http header

    I've a few questions regarding this header.
    1/ What is the point in using this header? Does it help with page ranking/hits?
    2/ Is if useful for static html pages or just for dynamic ones?
    3/ If it is useful for static pages, how do you add it? I.e exactly what code needs to added to the header? There seems to be quite a lot of discussion on the web about the merits or not of using this, but no examples of what code needs to be added.
    Any ideas?

    I hacked the Servlet myself so that it honors the if-modified-since header and returns HTTP-304 if the cached version is still ok.
    lg Clemens

  • If-Modified-Since HTTP Header

    Does anyone know if BC supports the if-modified-since http header? If it doesn't - how to add it to a BC webpage?
    In google guideline for SEo it states:
    Make sure your web server supports the If-Modified-Since HTTP header. This feature allows your web server to tell Google whether your content has changed since we last crawled your site. Supporting this feature saves you bandwidth and overhead.
    Thanks.

    I hacked the Servlet myself so that it honors the if-modified-since header and returns HTTP-304 if the cached version is still ok.
    lg Clemens

  • GetHttpRequestData missing "If-Modified-Since" and "If-None-Match"

    I'm using CF8 on IIS6/Win2003 Server.
    In my cfm I have:
    <cfset reqheaders=GetHttpRequestData().headers>
    <cfdump var="#reqheaders#">
    ...which gives:
    struct
    Accept
    text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
    Accept-Charset
    ISO-8859-1,utf-8;q=0.7,*;q=0.7
    Accept-Encoding
    gzip,deflate
    Accept-Language
    en-us,en;q=0.5
    Cache-Control
    max-age=0
    Connection
    keep-alive
    Cookie
    CFID=[removed]; CFTOKEN=[removed]
    Host
    [my test server]
    Keep-Alive
    300
    User-Agent
    Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3
    But if I look at the actual headers being sent from my browser (using Firefox LiveHTTP add-on), it shows I am sending "If-Modified-Since" and "If-None-Match" headers.
    GET /path/to/cfmfile.cfm HTTP/1.1
    Host: [removed]
    User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.6) Gecko/2009011913 Firefox/3.0.6
    Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
    Accept-Language: en-us,en;q=0.5
    Accept-Encoding: gzip,deflate
    Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
    Keep-Alive: 300
    Connection: keep-alive
    Cookie: CFID=[removed]; CFTOKEN=[removed];
    If-Modified-Since: Fri, 18 Sep 2009 01:18:19 GMT
    If-None-Match: ""0134E50193C69AD753656B0513FCB28C""
    Cache-Control: max-age=0
    Is there some reason IIS would "steal" those headers before handing over control to ColdFusion?  Or does GetHttpRequestData sometimes "miss" headers?  Other ideas?  Is there any other way I can get at the raw HTTP request from within ColdFusion?
    I'm at a loss.  Others have used the same process and no one seems to have this issue.
    (see: http://www.petefreitag.com/item/235.cfm or http://admin.mxblogspace.journurl.com/?mode=article&entry=1853 for examples)
    I've tried accessing the page using Internet Explorer instead.  It also is not showing those headers, but I have not sniffed IE's actual headers being sent so I can't be sure those headers are included (but I think they are, since IE implements conditional GET).

    Found out the answer.  IIS 6 does in fact steal "If-Modified-Since" and "If-None-Match" headers, but only on custom 404 redirects.  That's actually what I'm doing here (that'll teach me not to put details in a question when I think they're irrelevant -- actually I just forgot).
    Here's two discussions on the issue (they're using ASP, but apparently it's the same for ColdFusion):
    http://www.eggheadcafe.com/conversation.aspx?messageid=32839787&threadid=32839787
    http://www.webmasterworld.com/microsoft_asp_net/3935439.htm

  • 304 If-modified-since

    The following seems to be doing what it should i.e. comparing a modified-since header against a database value and sending a 304 if not modified accordingly. It appears to work but I would like your comments since I'm new to doing this type of thing.
    void doConditionalGet(java.sql.Timestamp ts, HttpServletRequest request,
    HttpServletResponse response) {       
            response.setDateHeader("Last-Modified", ts.getTime());
            long modifiedSince = -1;
            try {
                modifiedSince = request.getDateHeader("If-Modified-Since");
                if (modifiedSince != -1 && modifiedSince >= ts.getTime()) {               
                    response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
                    return;
            } catch (IllegalArgumentException iae) {
                log.error(iae);
        }Thank you
    Niklas

    The following seems to be doing what it should i.e. comparing a modified-since header against a database value and sending a 304 if not modified accordingly. It appears to work but I would like your comments since I'm new to doing this type of thing.
    void doConditionalGet(java.sql.Timestamp ts, HttpServletRequest request,
    HttpServletResponse response) {       
            response.setDateHeader("Last-Modified", ts.getTime());
            long modifiedSince = -1;
            try {
                modifiedSince = request.getDateHeader("If-Modified-Since");
                if (modifiedSince != -1 && modifiedSince >= ts.getTime()) {               
                    response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
                    return;
            } catch (IllegalArgumentException iae) {
                log.error(iae);
        }Thank you
    Niklas

  • Is it possible to find and Replace a string inside a textfile using JSP?

    FileInputStream fs = new FileInputStream("/opt/Abhishek/software/tomcat/webapps/AMS/listpass");
    DataInputStream in1 = new DataInputStream(fs);
    while (in1.available() !=0)
    String str1=in1.readLine();
    StringTokenizer st1 = new StringTokenizer(str1);
    String node=st1.nextToken();
    if (node.equals(sports))
    String pass=st1.nextToken();
    out.println ("<b>"+sports[i]+" <b>");
    out.println("**Your Required Password**");
    out.println(pass);
    out.println("<br></br>");
    %>
    Hi ,
    I have a text file (named listpass in the above code) inside tomcat-webapps folder containing a node name and its password.You could see the path of the text file at the starting line of the code.The Scene behind the program is once the particular node is clicked the password is retreived for the user against the particular node.What i would need is to change the password in the text file once it is retreived. So i would need to find the password that is retreived recently and change that one with a randomnly generated new password in the text file.
    So can i do this?Is it possible to search for the string in the text file and replace that with a new one using JSP.For your note i am running all my HTML amd JSP inside the same folder where i have the text file in which the string has to be replaced .
    Could anyone give your comments on this please?                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    Nasty in so many ways.
    First off you shouldn't be doing stuff like this in a JSP. JSPs should just build HTML, use a Servlet and then pass data to a JSP for formatting.
    Web applications are multi-threaded, so you have to consider what happens if several of these transactions come in at the same time, each trying to change the same data file.
    It's not practical to amend text files in place, generally you have to create a new version of the file for each change because if the size of a password changes the subsequent bytes of the file would all need moving.
    Use a database. Databases are designed to deal with these issues and there are perfectly good free ones around like Derby, MySQL and H2.

  • Could not access SOAP header - sending sopa message using weblogic

    i am using saaj to send a SOAP message ,through weblogic, i am getting an error like below
    Could not access SOAP header
    what should i do for sending a soap message using weblogic

    You're going to have to provide many more details than that. If it's useful, you could go here and read all the documentation books covering web services.

  • Sending automatic mail using JSP or Servlet

    hello,
    i was just wondering if anyone out there knows how can automatically send emails to client from my application after receiving thier email address. the email address is received from a form and i want my application to automatically send a structured email to the client as soon as they click the send button. i am using JSP and tomcat as my server. any help will be appreciated

    You must create a class that sends the mail:
    A code example would be like this:
    import javax.mail.Message;
    import javax.mail.MessagingException;
    import javax.mail.Session;
    import javax.mail.Transport;
    import javax.mail.internet.InternetAddress;
    import javax.mail.internet.MimeMessage;
    import java.util.*;
    public class MailSender {
         public void postMail(String smtpsrv, String recipients[], String subject,
                   String message, String from) throws MessagingException {
              boolean debug = false;
              //Set the host smtp address
              Properties props = new Properties();
              props.put("mail.smtp.host", smtpsrv);
              // create some properties and get the default Session
              Session session = Session.getDefaultInstance(props, null);
              session.setDebug(debug);
              // create a message
              Message msg = new MimeMessage(session);
              // set the from and to address
              InternetAddress addressFrom = new InternetAddress(from);
              msg.setFrom(addressFrom);
              InternetAddress[] addressTo = new InternetAddress[recipients.length];
              for (int i = 0; i < recipients.length; i++) {
                   addressTo[i] = new InternetAddress(recipients);
              msg.setRecipients(Message.RecipientType.TO, addressTo);
              // Setting the Subject and Content Type
              msg.setSubject(subject);
              msg.setContent(message, "text/html;charset=utf-8");
              Transport.send(msg);
    You 'll find out that its easy to understand the code.
    I advise you not to change this code.
    I also include an example of how to right the JSP code:
    <%
    MailSender MS = new MailSender();
    try {
         MS.postMail(server, recipient,"Your E-mail Title", "BODY content", from);
         } catch (MessagingException e1) {
                        e1.printStackTrace();
    %>
    This JSP code follows the pattern of the above class
    Hope to help you
    Cheers!!!

  • I'm having issues with iMessage. It works fine on wifi and I receive messages as iMessage without issue in network or wifi. However as I send a message it starts as iMessage then says not delivered. Then sends as SMS since I have it enabled.

    iMessage works on wifi without issue. However I receive messages on network but can't send. I send a message it starts sending as iMessage ten says it can't send. Then starts to send as SMS since it's enabled. I have reset network sertings, updated to ios7, etc and done about 3 othe suggested in order resets to get it to work and it still hasn't started working when I'm not on wifi. Any suggestions?
    It's a iPhone 4S. I have two iPhones. One setup to receive iMessage just to its phone number. Therapeutic to receive to its phone and email. I wouldn't think that would be the issue as all 3 are separate. Bone the same going to both phones.
    Thanks for the help!!!

    Hello there, pacotechguy.
    The following Knoweldge Base article provides great in-depth steps for troubleshooting your issue:
    iOS: Troubleshooting Messages
    http://support.apple.com/kb/ts2755
    Thanks for reaching out to Apple SUpport Communities.
    Cheers,
    Pedro.

  • I used migration to send photos form my Mac Book to my I Mac now i get an error message "iPhoto can not be opened because of a problem"  Check with the developer to make sure iPhoto works with this version of Max OSX.  You may need to install any availabl

    I used migration to send photos form my Mac Book to my I Mac now i get an error message "iPhoto can not be opened because of a problem"  Check with the developer to make sure iPhoto works with this version of Max OSX.  You may need to install any available updates or reinstall IPhoto.
    I tried installing Iphoto it said it was downloaded successfully. I still get the error messafe, and can not open any photos of program,  any suggestions?

    What version of iPhoto do you have on the Macbook and on the iMac? What systems are you running on the Macbook and on the iMac?
    Does the message only refer to "a problem" or does it specify what it is?
    Happy Holidays

  • Since i have updated to IOS 7.1 my phone no longer can make calls, connect using 3G or send text messages. can someone help please?

    since i have updated to IOS 7.1 my phone no longer can make calls, connect using 3G or send text messages. has anyone else had this trouble? i've tried resetting the phone, but had no luck. i can recieve calls and texts, but cannot make calls, text or use the 3G.
    please can anyone help?

    Yes! All the above. I have to buy a new phone. I contacted my phone company and there is nothing they can do 

  • Use sender from payload: Sender not in payload

    Hi,
    I am currently facing problems with a IDoc -> XI -> Proxy(XI) sceanrio.
    The Idoc is received by XI without any problems. No message mapping is required for this scenario. However, the message keeps getting stuck in the Inbound queue (SMQ2). The status text says "Use sender from payload: Sender not in payload".
    Can anyone help me out on this?
    Thanks,
    Krishneel

    Check this related problem:
    ATTRIBUTE_IDOC_METADATA : Sender not in payload
    Regards,
    Abhishek.

  • Use sender in Payload: Sender not in Payload.

    Hi,
    When R3 sends ORDRSP to XI , the BPM in XI sends a Status ( SYSTAT01 IDoc ) back to R3 without any problem. Whereas when R3 sends DELVRY03 to XI, the BPM in XI is not able to send the Status back to R3  and gets stuck in XI Queue. The reason: Use sender in Payload: Sender not in Payload.
    Both ORDRSP and DELVRY03 are using the same IDOC Receiver Channel with Take Sender from Payload checked.
    Any idea what is causing the message to get stuck in the queue.
    Thanks,
    Sreekanth

    The reason: Use sender in Payload: Sender not in Payload.
    Check below link:
    Error: Sender Not in Payload
    also there are other threads...but ultimately it is Michal's reply which everyone is refering to.
    Regards,
    Abhishek

Maybe you are looking for

  • Update a block without navigating to it.

    I have a table with several integers in it and a Form that reads the table. The Form has to translate the integers into things the user wants to see, so I hide the actual database field, do a translation into the user friendly string and display it i

  • PSE 4 - Automatic Red-Eye Correction

    When I import photos into the organize, the program automatically fixes the red eye. Is there a way to disable it from automatically correcting the red eye? Thanks

  • I tunes Match im getting error 4001?

    Itunes Match im getting error 4001 and it will not let me match my songs.?

  • MDS Schema Configuration Failue during OEM installation

    During the OEM installation the set-up stops at MDS Schema Configuration. I see the following exception in the log files :-( emmdscreate_2010_08_25_AD_23_11_09_IST.log* 2010_08_25_AD_23_11_09_IST EMMDSSchemaManager: Info : Oracle Home is C:\Oracle\Mi

  • How to restrict save on fbcj

    Dear All... how to restrict save on T-code:  fbcj thanks & best regards, Qwashty