Link to home
Start Free TrialLog in
Avatar of archrajan
archrajan

asked on

BROWSER BACK

Hi i wud like to know a way by which i cud
reload the page fresh from the server eachtime the user clicks the browser 's back button..
i cannot have links to go back...
i want it with the browsers back button...

right now whenever i click back the page reloads from cache... and its not going to the server again..
any help is deeply appreciated
Avatar of dfu23
dfu23

in your web pages try using this:

<head>
  <meta http-equiv="Expires" CONTENT="0">
  <meta http-equiv="Cache-Control" CONTENT="no-cache">
  <meta http-equiv="Pragma" CONTENT="no-cache">
</head>
SOLUTION
Avatar of Kuldeepchaturvedi
Kuldeepchaturvedi
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of archrajan

ASKER

it doesnt work for me...
i put those lines in the head of my page
Try adding a dummy variable with your URL..

something like http://localhost:8080/mypage.jsp?dummy=dummy.

As I said back button is a browser function and browser itslef handles it.. All we can try is to tell browser not pick it up from cache ( thats what we tried to do by putting those lines in the response..) it should have worked.
One more thing that you should do is to go to tools-->internet options-->settings
and select the radio button which says 'every visit to the page'.

These settings should work
ASKER CERTIFIED SOLUTION
Avatar of TimYates
TimYates
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
TimYates do i add it in the head section? in both the jsp files...
Yeah, that should do!

Personally, I have an HttpFilter which adds it to the response for every request to my webapp...

But adding it to the top (before <HTML>) should do it :-)
>>  TimYates do i add it in the head section?

Add it before all the rest of the page;

----

<%
        // Set to expire far in the past.
        response.setHeader("Expires", "Sat, 6 May 1995 12:00:00 GMT");
        // Set standard HTTP/1.1 no-cache headers.
        response.setHeader("Cache-Control", "no-store, no-cache, must-revalidate");
        // Set IE extended HTTP/1.1 no-cache headers (use addHeader).
        response.addHeader("Cache-Control", "post-check=0, pre-check=0");
        // Set standard HTTP/1.0 no-cache header.
        response.setHeader("Pragma", "no-cache");
%>
<HTML>
    <HEAD>
        <TITLE>Woo!</TITLE>
etc...
Normally I put them in a filter and applies it to all the pages... Works for me!!
package org.whatever ;

import javax.servlet.Filter ;
import javax.servlet.FilterChain ;
import javax.servlet.FilterConfig ;
import javax.servlet.ServletException ;
import javax.servlet.ServletRequest ;
import javax.servlet.ServletResponse ;
import javax.servlet.http.HttpServletRequest ;
import javax.servlet.http.HttpServletResponse ;

import org.apache.commons.logging.Log ;
import org.apache.commons.logging.LogFactory ;

public class RequestFilter implements Filter
{
  private static Log log = LogFactory.getLog( RequestFilter.class ) ;

  private FilterConfig filterConfig;

  public void doFilter( final ServletRequest req, final ServletResponse res, FilterChain chain ) throws IOException, ServletException
  {
    HttpServletRequest response = (HttpServletResponse)res ;
   
    // Set to expire far in the past.
    response.setHeader("Expires", "Sat, 6 May 1995 12:00:00 GMT");
    // Set standard HTTP/1.1 no-cache headers.
    response.setHeader("Cache-Control", "no-store, no-cache, must-revalidate");
    // Set IE extended HTTP/1.1 no-cache headers (use addHeader).
    response.addHeader("Cache-Control", "post-check=0, pre-check=0");
    // Set standard HTTP/1.0 no-cache header.
    response.setHeader("Pragma", "no-cache");

    chain.doFilter( request, response ) ;
  }

  public void setFilterConfig( final FilterConfig filterConfig )
  {
    this.filterConfig = filterConfig ;
  }

  public void init( FilterConfig config )
  {
    this.filterConfig = config ;
  }

  public void destroy()
  {
    this.filterConfig = null ;
  }
}

Then, in web.xml:

  <filter>
    <filter-name>requestfilter</filter-name>
    <filter-class>org.whatever.RequestFilter</filter-class>
  </filter>
  <filter-mapping>
    <filter-name>requestfilter</filter-name>
    <url-pattern>*.jsp</url-pattern>
  </filter-mapping>