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 7817049
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T06:05:57+00:00 2026-06-02T06:05:57+00:00

I am using filter that check if user is log in then don’t cache

  • 0

I am using filter that check if user is log in then don’t cache the previous page. The code for this is like,

public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain)
        throws IOException, ServletException {
    ....
    if (isRegisteredUser.equalsIgnoreCase(("1"))) {

        sessionID = UUID.randomUUID().toString();

        session.setMaxInactiveInterval(1800); 

        Cookie userCookie = new Cookie("userCookie", "loginUser");
        userCookie.setPath("/");
        httpServletResponse.addCookie(userCookie);

        Cookie sessionCookie = new Cookie("WITSessionCookie", sessionID);
        sessionCookie.setMaxAge(60*30);  
        sessionCookie.setPath("/");    
        httpServletResponse.addCookie(sessionCookie);

        if (!httpServletRequest.getRequestURI().startsWith(httpServletRequest.getContextPath() + ResourceHandler.RESOURCE_IDENTIFIER)) { // Skip JSF resources (CSS/JS/Images/etc)
            httpServletResponse.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1.
            httpServletResponse.setHeader("Pragma", "no-cache"); // HTTP 1.0.
            httpServletResponse.setDateHeader("Expires", 0); // Proxies.
        }

        filterChain.doFilter(httpServletRequest, httpServletResponse);

    }
    ...

} //end of doFilter()

But the problem is, if on any page user click on any button or link, and I return null for that action, and then I click on browser back button, then it says page expires. How can I prevent this? It is fine, that the page is not caching, but why it expires my page when I click on any button or any link and return null for that action?
Thanks

  • 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-02T06:05:59+00:00Added an answer on June 2, 2026 at 6:05 am

    That’s normal and specified behaviour when the enduser attempts to re-send a POST request which is not cached in the browser. You need to implement the post-redirect-get pattern. Send a redirect to the destination page in the action method. Or, better, make it an ajax submit instead. This is by the way regardless of whether you return to the same view by returning null or not.

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

Sidebar

Related Questions

Scraping pages using BeautifulSoup; trying to filter out links that end in ...html#comments Code
I'm using a filter in web.xml to check if a user is logged in
I have an ISAPI filter that I am using to do URL rewriting for
I have an application that can filter a datagridview based on date using a
I'm trying to create a regular expressions that will filter valid emails using PHP
I have an IEnumerable<DirectoryInfo> that I want to filter down using an array of
I want to ask that i am using core image and applying some filter
Imagine the following scenario. I have a checkbox that the user can check to
I'm using the following code to send push notifications to the user... document.triggerNotification =
I'm trying to implement email confirmation using Pyramid framework. Here's the code that confirms

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.