Am Donnerstag, 9. Januar 2003 16:36 schrieb KEITH KOSMICKI:
> I have a button on a page that uses location.href to go to other pages.
> One of these buttons options goes to the previous page.
> However, it loads the page out of history rather than loading a new page
> from the server.url Replace does not work and gives syntax error and other
> options so far load a blank page. Any suggestions.
Obviously, the previous page was cached. For dynamic pages that should
be requested again each time, you have to tell the browser | proxy that it
shouldn't use the cache. Unfortunately, the mechanism is not standardized,
but putting the following lines in your JSP page somewhere before
sending body content should normally suffice:
<%
response.addHeader("Pragma", "no-cache");
response.setHeader("Cache-control", "no-cache");
response.setDateHeader("Expires", 0);
%>
There is a fourth possible line which I saw once but don't remember
right now, but that's kind of esoteric anyway. As this is a common task,
you can also write a handy little tag for such stuff, as described in
O'Reilly's JSP book, for example (www.TheJSPBook.com). If the
page in question is static HTML, those lines should go into <META>
tags in the <HEAD> section of your page.
HTH,
-- Chris (SCPJ2)
OK, I'll also add the code for my own solution. Most parts are
generated by Sun ONE Studio, as I was lazy and used the
wizard, so the code is kind of verbose. But still. Here it comes:
package de.christianbollmeyer.tags;
import javax.servlet.jsp.tagext.TagSupport;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.PageContext;
import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.tagext.BodyTagSupport;
import javax.servlet.jsp.tagext.BodyContent;
import javax.servlet.jsp.JspWriter;
import java.io.PrintWriter;
import java.io.IOException;
import javax.servlet.jsp.tagext.Tag;
import javax.servlet.jsp.tagext.IterationTag;
import javax.servlet.jsp.tagext.BodyTag;
public class NoCacheTag extends TagSupport {
public NoCacheTag() {
super();
}
// doStartTag()
public void otherDoStartTagOperations() {}
public boolean theBodyShouldBeEvaluated() {
return false;
}
// doEndTag()
public void otherDoEndTagOperations() {
HttpServletResponse rsp
= (HttpServletResponse)(Object) pageContext.getResponse();
rsp.addHeader("Pragma", "No-cache");
rsp.addHeader("Cache-Control", "no-cache");
rsp.addDateHeader("Expires", 0L);
}
public boolean shouldEvaluateRestOfPageAfterEndTag() {
return true;
}
// doAfterBody()
public boolean theBodyShouldBeEvaluatedAgain() {
return false;
}
/** .//GEN-BEGIN:doStartTag
*
* This method is called when the JSP engine encounters the start tag,
* after the attributes are processed.
* Scripting variables (if any) have their values set here.
* @return EVAL_BODY_INCLUDE if the JSP engine should evaluate the tag
body, otherwise return SKIP_BODY.
* This method is automatically generated. Do not modify this method.
* Instead, modify the methods that this method calls.
*
*/
public int doStartTag() throws JspException, JspException {
otherDoStartTagOperations();
if (theBodyShouldBeEvaluated()) {
return EVAL_BODY_INCLUDE;
} else {
return SKIP_BODY;
}
}//GEN-END:doStartTag
/** .//GEN-BEGIN:doEndTag
*
*
* This method is called after the JSP engine finished processing the tag.
* @return EVAL_PAGE if the JSP engine should continue evaluating the JSP
page, otherwise return SKIP_PAGE.
* This method is automatically generated. Do not modify this method.
* Instead, modify the methods that this method calls.
*
*/
public int doEndTag() throws JspException, JspException {
otherDoEndTagOperations();
if (shouldEvaluateRestOfPageAfterEndTag()) {
return EVAL_PAGE;
} else {
return SKIP_PAGE;
}
}//GEN-END:doEndTag
}
> Best,
>
>
> Keith E. Kosmicki
> Applications Consultant
> State of IL Human Services
> STL Technology Partners
>
>
> To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
> JSP-INTEREST". For digest: mailto [EMAIL PROTECTED] with body: "set
> JSP-INTEREST DIGEST". Some relevant FAQs on JSP/Servlets can be found at:
>
> http://archives.java.sun.com/jsp-interest.html
> http://java.sun.com/products/jsp/faq.html
> http://www.esperanto.org.nz/jsp/jspfaq.jsp
> http://www.jguru.com/faq/index.jsp
> http://www.jspinsider.com
==========================================================================To
unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:
http://archives.java.sun.com/jsp-interest.html
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.jsp
http://www.jguru.com/faq/index.jsp
http://www.jspinsider.com