Apache caching in jsp

my first problem :
is whenever i update/debug or simply add a new code to my .jsp file, i can't immediately see its output what i do get is an old page. for example, sample.jsp contains 2 submit buttons and then i deleted one button but when i run my sample.jsp page it still displays 2 submit.
my theory:
so far, i think it has something to do w/ the cache because when i restarted my apache, i can now see one button.
my next problem:
if that's the case, then all users of my site have to restart their apache and i think this totally defeats the purpose of my site in the first place. it will only make things more complicated.
my plea:
can somebody help me???
thanks

it is often necessary... The browser cache should be ignored by shift click/ shift reload, but if you are behind a firewall or proxy server that caches files, then no matter how hard you press the shift key, it won't tell the firewall cache to go to the server. I don't know that there is a caching firewall in this circumstance, but unless it's for a intranet that you really know about, you can't assume that people won't be hitting the site from the other side of a caching firewall. This would be totally transparent to the user (and his/her browser). Which is why if I have a JSP page or servlet (which nearly always has content I won't want cached) I include the no-cache headers to tell any cache to not store the file.
response.setHeader("Cache-Control", "no-cache");
response.setHeader("Pragma", "no-cache");
response.setDateHeader("Expires", 0);
between the 3 lines, it should take care of browser cache and proxy cache.

Similar Messages

  • How can I throw a hard 404 error to apache when a JSP is not found.

    How can I throw a hard 404 error to apache when a JSP is not found.
    I want to let apache handle the error.

    [email protected] (Jeremy Conner) wrote in
              <[email protected]>:
              >How can I throw a hard 404 error to apache when a JSP is not found.
              >I want to let apache handle the error.
              >
              >
              First thought that comes to mind is to return HTML that tells the browser
              redirect to a nonexistent file under Apache. You can't tell Apache to
              throw a 404 unless you're in a mod. Maybe something they could add to the
              proxy, but until then, I think a redirection in the response HTML is your
              only option.
              Jesse
              

  • Control client cache for JSP

    There are many threads on the web about how to force a reload rather than pulling content from cache. My problem is the opposite. I am trying to get good cache control for a jsp application that has relatively static contents. My goal is to serve up pages with the following characteristics:
    For client calls:
    If there is no version in cache, the jsp builds a new version and sets the response date header "Expires" to 5 days later.
    If within the Expires date, have the client just use the cached version: no validation or roundtripping.
    If after the Expires date, roundtrip: have the jsp return 303 (SC_NOT_MODIFIED) if no content changed. Also, ideally, also reset the Exipres date to an additional 5 days.
    Otherwise, recreate the response and start over...
    I am experiencing different behaviors with different browsers, although none act as I was hoping.
    When there is no relevant page in cache, all of the browsers accept a new version (and I think that they all put it in cache). All browsers reload the page using the reload button.
    If there is a relevant page in cache and it has not expired:
    1. FireFox 3 seems to roundtrip, but then use the version in cache.
    2. IE 7 seems to always use the cache version without checking the server
    3. Google Chrome seems to always roundtrip and reload.
    I tried several variations including setting/not setting the Last-Modified date header and setting/not Cache-Control: no-control header (to force validation).
    Neither Last-Modified nor no-contro: NO CHANGE FROM ABOVE;
    Last-Modified set, no-control not specified: NO CHANGE
    Last-Modified not set, Cache-Control set to no-control to force validation.
    The main problem here is that I was unable to get a value for the request header "Last-Modifier" so that my jsp could not set the 303 return, therefore all browsers roundtrip and reload.
    SO...
    1. What do I need to do to get all browsers to pull from cache and not roundtrip prior to the Expires date?
    2. After the Expires date, what do I need to do to get the request to include the Last-Modified date header sent to the server?
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><%
    %><%@ page import="java.net.*"%><%
    %><%@ page import="java.util.*"%><%
    %><%@ page import="java.util.Date"%><%
    %><%@ page import="javax.servlet.*"%><%
    %><%@ page import="java.text.SimpleDateFormat" %><%
    //  In a real application, the updatedDate would come from a database or file
    Calendar thisCal = new GregorianCalendar();
    thisCal.set(2009,02,15);
    Date     updateDate = thisCal.getTime();
    //  This never returns a valid date
    long  thisLongDate  = request.getDateHeader("Last-Modified");
    Date  cachedDate    = ((thisLongDate<0)?null:new Date(thisLongDate));
    Date  todaysDate    = new Date();
    //  Show all three dates in the output
    String   outString = "";
    SimpleDateFormat   showDateFormatter = new SimpleDateFormat ("yyyy-MM-dd hh:mm:ss");
    outString += "================================================================<br> \n";
    outString += " Start TestSuite25.jsp "+showDateFormatter.format(todaysDate)+"<br> \n";
    outString += "Update date is "+showDateFormatter.format(updateDate)+"<br> \n";
    outString += "Cached date is "+((cachedDate==null)?null:showDateFormatter.format(cachedDate))+"<br> \n";
    response.setContentType("text/html");
    if (request.getParameter("lastmodified") != null)
       outString += "Set Last Modified header:  may trigger If-Modified-Since request. <br> \n";
       response.setDateHeader("Last-Modified",updateDate.getTime());
    //  force validation .. does this hit my code??
    if (request.getParameter("cache") != null)
        outString += "Set cache control to no-cache to force validation on every call<br> \n";
        response.setHeader("Cache-Control", "no-cache");
    //  use cache for 5 days, then validate
    thisCal.setTime(todaysDate);
    thisCal.add(Calendar.DATE,5);
    response.setDateHeader("Expires", thisCal.getTime().getTime());
    //  Check for still fresh on server
    if (!(cachedDate == null) && (!cachedDate.before(updateDate)))
       outString += "Contents are unchanged: send 303 status message<br> \n";
       response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
       System.out.println(outString);
    else
       outString += "Rebuild and send the HTML <br>";
       System.out.println(outString);
       // Build and send the HTML ...
    %>
    <html>
    <head>
      <title>Test suite</title>
      <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
    </head>
    <body >
    <br>
    <h2 align="center">Test 25: Controlling Cache</h2>
    <h3 align="center">Click <a href="TestSuite21.html">here</a> to continue to Test 26.</h3>
    useage: TestSuite25.jsp<br>
    optional parameters: <br>
       cache=nocache: include no-cache to force validation each time<br>
       lastmodify=set:  include Last-Modified date hearer<br>
    <br>
    <%=outString%>
    </html>
    </body>
    <% } %>

    let me tell you from BSP side !
    within your BSP application set a javascript timer for 2 minutes and upon completion run a javascript to kill the backend session along with the SSO2 cookie.
    check the BSP application system/session_single_frame.htm
    for a javascript named "exitBSPApplication"
    Hope this is helpful.
    Regards
    Raja

  • Login in apache james using jsp

    how to make user log in apache james through jsp.
    any idea will be very helpful.

    JavaMail comes with a web app that uses JSPs, as well as a simple
    servlet app. Both of them handle logging in to the mail server.
    Did neither of them help you? Apache James is just another
    mail server.
    There's also pointers on the JavaMail web page to several tutorials
    and articles that will help.

  • Cache  Problem-JSP

    Hi All,
    I am developing a web application using JSP and Flash
    In Flash i had given links for various countries
    Once the user clicked the link session for language
    and country is set..
    since v have only five links i call separate jsp file for
    each click
    this works fine for some time
    but some time it won't
    i checked each time..
    And found the problem is b'ze of tht history in IE[cache]
    Is there any way to clear tht cache using JSP or by any way thru coding
    I used out.clear(),out.clearBuffer() and all it won't worked
    out
    Hope number of ppls r there to help
    expecting a quick reply
    make a mail to me at
    [email protected]
    Friendly
    Arul

    Set the following scriptlet on every page...
    <%
    response.setHeader("Cache","NoClear");
    response.setHeader("Pragma","NoClear");
    response.setDateHeader("Expires",0);
    %>

  • Problems with Apache and custom JSPs

    Hi
    We've made an application on top of IFS, using JWS in our test envirnment. Just before making some stress tests, I'd like to try it using Apache. We're currently having two problems:
    1) I switch to the apache configuration running ifsconfig and not selecting JWS. When I try to access the ifs using http://host/ifs/files, everything goes well except that the "logout" icon doesn't appear. I did a little research and found out that the link goes to /ifs/webui/images/logout.gif. This gives an error in mod_jserv.log, like this one:
    [07/06/2001 22:54:20:315] (ERROR) ajp12: Servlet Error: ClassNotFoundException: webui
    It seems it's trying to find a "webui" class, since in ifs.properties every url that begins with /ifs goes to jserv.
    I don't know if this is a know problem or what should I've check...
    2) This one is more important. We're using some custom JSPs, which we use to edit the properties of some types of documents. Basically, when the user clicks over a file one of our JSP appears. These JSPs call a bean to do some processing, passing the HttpRequest as a parameter. The problem is that when using JWS we get the "path" request variable like in path=/%3A29464
    However, when using Apache we get path=/ifs/files/%3A29464 ( and afterwards we get an exception because the ifsSession.getPublicObject method doesn't work).
    Any hints on this? One way could be to check if the path begins with /ifs/files, but that's not really nice.. and besides I could have the same problem in some other parts.
    It's kind of urgent....
    Thanks
    Ramiro
    null

    Hi,
    The answer to your path problem is that you can make use of API to find out the current path so that it works both with Apache and with JWS. Follow the steps
    1. import the oracle.ifs.adk.http package in your custom jsps
    <%@ page import = "oracle.ifs.adk.http.*" %>
    2. Then within your jsp use the method
    getIfsPathFromJSPRedirect
    <%= oracle.ifs.adk.http.HttpUtils.getIfsPathFromJSPRedirect(request) %>
    This will give you the current path of the object on which you clicked on and which initiates the custom jsp.
    You can look at the CMS application which has made use of this API. URL is
    http://otn.oracle.com/sample_code/products/ifs/sample_code_index.htm
    Choose, sample applicatin -> Content Management system.
    Hope this helps
    Rajesh
    null

  • How to implement content caching for jsp page ?

    Hello everyone,
    I am reading an article <Servlets and Jsp Best Practice>,at
    http://developer.java.sun.com/developer/technicalArticles/javaserverpages/servlets_jsp/#author, on one section it is saying :
    "Cache content: You should never dynamically regenerate content that doesn't
    change between requests. You can cache content on the client-side, proxy-
    side,or server-side. "
    Now I am working on a project. For every user, some of the content servlet generated will be the same for at least a week . I am thinking if I implement caching for these jsp pages, that would increase performace a lot.
    But I have no idea how to implement it either client-side or server-side, can someone give me a hint ?
    Thanks,
    Rachel

    You mean actually you are caching the response stream
    and the key to distinguish between different response
    streams are made of user's different request
    parameters. And the filter's function is to intercept
    the request to see if this request parameter's
    combination already exists in the Hashmap,then either
    use the cached response or forward to
    servlet.....really interesting...Do I get it right ?Yes that's it in a nutshell.
    >
    Then how do you build those response streams in
    advance ? You did it manually or have some mechanism
    to build it automatically ?
    The data gets cached the first time somebody visits the page.
    Find some examples on Filters, and take a look at the HttpServletResponseWrapper class. You need to cache response headers as well as the body. Another pitfall that you might run into is handling an If-modified-since header on the request. Don't cache the results of those requests.
    -Jonathan
    >
    Thanks again !
    Rachel

  • File Caching in JSP

    Hi,
    I view a bunch of PDF's in my JSP file which can then be modified according to the user needs. For example, the user views a PDF file, then he/she can remove some documents within the pdf which will contact a Bean, remove the documents, recreate the PDF and save it with the same path and name. However, when I try to view the file, it still displays the old one although the new file gets created successfully when I check in my directory... any inputs on how I can avoid this problem?
    THanks,
    YAsir

    I am using the following code to disable cache,. is that any different from the one you sent?
    I think its more of a "PDF file opening up in a browser" kinda problem
    thanks though
    <%
    response.setHeader("Cache-Control","no-cache"); //HTTP 1.1
    response.setHeader("Pragma","no-cache"); //HTTP 1.0
    response.setDateHeader ("Expires", 0); //prevents caching at the proxy server
    %>

  • Aggressive Caching of JSP Custom Tags?

    I've just developed my first JSP Custom Tag. I compiled my class and it
              worked fine. But subsequent changes to the class source and recompiles
              don't affect the JSP output; evidently, these are aggressively cached, so
              much so that 12 hours later it still won't change (I was hoping it would be
              a 10 minute timeout or something like that.)
              Is this the problem? If so, is there a weblogic.properties setting to tell
              WL to check for modifications to the class file every so often?
              David
              

    Lets say i want to have some user defined exception messages.There
    i will say in tag support or body tag support i will use JSPException
    and throw my customised exception.
    Can any one tell me any practical example.
    If someone really have used it somewhere.
    thanks
    vijendra

  • Image caching in JSPs

    In WL6 sp2, we have JSP pages that call an ImageServlet within the <IMG> tag
              to pull JPG files from the database to the local filesystem and create an
              outputstream so that they are displayed on the page.
              The problem is that the servlet is not called each time the page loads.
              Only if a Refresh is requested will the servlet be called that displays the
              image. Our browsers are set not to cache pages, and the page has the usual
              no-cache pragmas.
              My question is, are images cached in the compiled servlet code? Is there
              something about the WebLogic HTTP server that prevents an <IMG> from being
              loaded each time the page is delivered?
              

              Turns out that Nscp 4.7 has a nasty habit of caching images even if it isn't
              supposed to. We don't have this problem in IE.
              "Sam Pullara" <[email protected]> wrote in message
              news:[email protected]...
              > There is nothing in the server that is caching the pages. This must be a
              > browser related behavior. You can see if a request is being made from the
              > browser by looking at the access log. Are you setting the no-cache pragma
              > on the servlet that is serving the .jpg files?
              >
              > Sam
              >
              > "Tony Bailey" <[email protected]> wrote in message
              > news:[email protected]...
              > > In WL6 sp2, we have JSP pages that call an ImageServlet within the <IMG>
              > tag
              > > to pull JPG files from the database to the local filesystem and create
              an
              > > outputstream so that they are displayed on the page.
              > >
              > > The problem is that the servlet is not called each time the page loads.
              > > Only if a Refresh is requested will the servlet be called that displays
              > the
              > > image. Our browsers are set not to cache pages, and the page has the
              > usual
              > > no-cache pragmas.
              > >
              > > My question is, are images cached in the compiled servlet code? Is
              there
              > > something about the WebLogic HTTP server that prevents an <IMG> from
              being
              > > loaded each time the page is delivered?
              > >
              > >
              >
              >
              

  • Org.apache.jasper.JasperException: /jsp/common/GL_nomineeaccessallowForm.js

    <%@ page language="java" %>
    <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
    <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
    <%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
    <%@ page import="com.tcs.KIA.common.VO.TM_viewVO" %>
    <%@ page import="com.tcs.KIA.common.VO.GL_nomineeaccessallowVO" %>
    <%@ page import="java.util.ArrayList" %>
    <html>
    <head>
    </head>
         <body bgcolor="efefef">
         <html:errors/>
         <center>
         <html:form action="/GL_nomineeaccessallowAC.do" enctype="multipart/form-data">
         <%!
              GL_nomineeaccessallowVO v=null;
              ArrayList view=null;
              String empid=null;
         %>
         <%empid=(ArrayList)request.getSession().getAttribute("empid");%>
         <table cellpadding="2" cellspacing="1" border="0" align="center">
              <tr bgcolor="#95B1FF">
                   <td><b>Employee ID</b></td>
                   <td><html:text property="empid"></td>
              </tr>
              <tr bgcolor="#95B1FF">
                   <td><b>Project Owner Employee ID</b></td>
                   <td><html:text property="ownerno"></td>
              </tr>
         </table>
    <html:submit>Submit</html:submit>
    <html:reset>Reset</html:reset>
    </center>
    </html:form>
    </body>
    </html>
    Please help me find the error.

    You don't really provide enough info to solve the problem ... but hey, you've showed me enough to stay away from tata ...

  • JSP caching on Apache

    Hi,
    We are getting inconsistent caching of our JSP's on APACHE.
    Here is a sample response header.
    HTTP/1.1 200 OK
    Date: Fri, 04 Mar 2005 11:57:16 GMT
    Server: Apache Tomcat/4.0.1 (HTTP/1.1 Connector)
    Content-Type: text/html; charset=utf-8
    Cache-Control: max-age=7200, must-revalidate
    Last-Modified: Fri, 04 Mar 2005 11:53:45 GMT
    Expires: Fri, 04 Mar 2005 13:53:45 GMT
    Content-Length: 22396
    Age: 1073
    I would expect the JSP to expire after two hours but Apache seems to randomly expire the page after 2-50 minutes.
    Here are our APache cache settings :-
    CacheRoot               /cache               
    CacheSize               15000000
    CacheGcInterval               4
    CacheMaxExpire          24
    CacheLastModifiedFactor     1
    CacheDefaultExpire          24
    CacheDirLevels               not set
    CacheDirLength               not set
    CacheNegotiatedDocs          on
    NoCache               not set
    Any help/suggestions much appreciated.

    Make sure you only have one instance of PageContext in your classpath.
    Check all the jars in your classpath. I know that orion.jar has an instance of PageContext that you should remove.

  • Caching issue in jsp or servlet

    I am not sure where I should post the issue that I have. I have a j2ee web app (struts) running on Apache Web Server + Glassfish + MySQL. My server has multi core.
    The problem is that whenever I insert a new data or delete it from a table, I don't see the change right away. Sometimes, I see the change. Sometimes I don't. It's very inconsistent.
    If the old data is cached in JSP, I shouldn't see the change in log file, but I do see it even in the log file.
    For example, I have a page managing user's folders. when I delete a certain folder name from jsp page, this folder is deleted from a db table. but when I refresh the page, I still see the folder name that is not supposed to show up. or when I go to a different page and come back to this page, I don't see it. The behavior is very inconsistent.
    If it's a browser caching issue, I don't think that I should see it in the log file, but I still see the folder name(which is supposed to be deleted) in the log file.
    I am including these lines in all included jsp pages.
    response.setHeader("Cache-Control","no-cache");
    response.setHeader("Pragma","no-cache");
    response.setDateHeader ("Expires", -1);
    does anybody have any opinion about this?
    It's hard to debug it and describe the behavior.
    But it would be very helpful if someone who had a same experience about this explains about this and tells me how to fix it.
    Thanks.

    caesarkim1 wrote:
    I am including these lines in all included jsp pages.
    response.setHeader("Cache-Control","no-cache");
    response.setHeader("Pragma","no-cache");
    response.setDateHeader ("Expires", -1); Instead of including these lines in all jsp's, make a filter and add these lines to it.

  • Can and jsp in Apache??how to do?

    Thank you!

    Your subject is vague. But if i understand your right.
    The answer is no. You will need to have Tomcat in
    conjunction with Apache to run jsps.
    Please read the docs @
    http://jakarta.apache.org/
    http://httpd.apache.org/
    amlan

  • How to disable browser caching for a specific JSP

    Is it possible to keep the browser from caching a JSP? If so how?

    you can put
    response.setHeader("pragma","no-cache");
    response.setHeader("cache-content","no-cache");
    response.setHeader("expires",0);
    in your jsp that will do..

Maybe you are looking for