Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7876027
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:06:07+00:00 2026-06-03T03:06:07+00:00

To prevent Login screen on my application from being cached by the browser i’m

  • 0

To prevent Login screen on my application from being cached by the browser i’m using the following peace of code :

public class SessionHandler implements Filter {


public void init(FilterConfig filterConfig) throws ServletException {
}

public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException {
    if ((request instanceof HttpServletRequest) && (response instanceof HttpServletResponse)) {
    .
    .
    .
    try {
        HttpServletRequest httpReq = (HttpServletRequest) request;
        HttpServletResponse httpRes = (HttpServletResponse) response;

        //ignore images/css...etc
        if(!httpReq.getRequestURI().startsWith(httpReq.getContextPath() + ResourceHandler.RESOURCE_IDENTIFIER)){
            //if login screen or home - don't cache 
            if(httpReq.getRequestURI().equalsIgnoreCase("/jsp/auth_login.faces")
                    || httpReq.getRequestURI().equalsIgnoreCase("/jsp/def_home.faces") ) {


                System.out.println(httpReq.getRequestURI() + " ----- " + " WON'T BE CACHED");

                httpRes.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1.
                httpRes.setHeader("Pragma", "no-cache"); // HTTP 1.0.
                httpRes.setDateHeader("Expires", 0); // Proxies.                    
            }
        }           
        filterChain.doFilter(request, response);
    ...

Using code I’ve found in one of the questions answered here by BalusC to prevent caching. My problem is that it seems the page is still being cached by the browser. Using Chrome Developer Tools to view HTML header of page i see the following on initial page load:

enter image description here

and if go back to login page after successful login i see:

enter image description here

Is anyone able to tell me why the login page is being cached?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T03:06:09+00:00Added an answer on June 3, 2026 at 3:06 am

    Problem was caused due to implicit lookup of request URI where in cases in which the application was not deployed under root path the logic was not being used.

        if(!httpReq.getRequestURI().startsWith(httpReq.getContextPath() + ResourceHandler.RESOURCE_IDENTIFIER)){
            //if login screen or home - don't cache 
            if(httpReq.getRequestURI().equalsIgnoreCase("/jsp/auth_login.faces")
                    || httpReq.getRequestURI().equalsIgnoreCase("/jsp/def_home.faces") ) 
    

    was changed to:

        if(!httpReq.getRequestURI().startsWith(httpReq.getContextPath() + ResourceHandler.RESOURCE_IDENTIFIER)){
            //if login screen or home - don't cache 
            if(httpReq.getRequestURI().endsWith("/jsp/auth_login.faces")
                    || httpReq.getRequestURI().endsWith("/jsp/def_home.faces") ) 
    

    and it’s all working as intended.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing an application where you need to show login screen modally and
Background We have a WinForms application with Entity Framework 4.2 code-first / FluentAPI using
I have a login screen and i am authenticating users by checking credentials from
Im my application I have the following code, the first bit runs when my
I have the following code in application didFinishLaunchingWithOptions where I want to present a
I want to prevent users from signing up with a password = login for
I am using FormsAuthentication to prevent anonymous users from accessing any content on my
How to prevent Javascript Menu from getting hidden under Flash Video (SWFObject ). I
Is is possible to prevent Wget from making an output file when there is
If one can prevent subclassing by declaring private constructor in the base class, why

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.