0

everyone.

In my JSF application, I use commandButtons to submit forms, process the data in the managed bean, and display result pages. When the user is in one of these resulted pages and presses the back button, the browser displays a message asking to resubmit the form. Is there any way to avoid this? I have searched but haven't found a solution yet.

In the application, there is a filter class that prevents to go back in pages after the user logs out. Is there any relation of this method with the problem mentioned above?

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        LoginController loginController = (LoginController) ((HttpServletRequest) request).getSession().getAttribute("loginController");
        HttpServletResponse  res = (HttpServletResponse) response;
        res.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1.
        res.setHeader("Pragma", "no-cache"); // HTTP 1.0.
        res.setDateHeader("Expires", 0); // Proxies.
        //System.out.println("prevent caching");
        if(loginController == null || !loginController.isLoggedIn()){
            String contextPath = ((HttpServletRequest) request).getContextPath();
            ((HttpServletResponse) res).sendRedirect(contextPath + "/index.xhtml");
        }
        else {
            chain.doFilter(request, res);
        }
    }

I appreciate any help.

mordecai
  • 529
  • 5
  • 25
  • Possible duplicate of [How to avoid re-execution of last form submit action when the page is refreshed?](https://stackoverflow.com/questions/7850831/how-to-avoid-re-execution-of-last-form-submit-action-when-the-page-is-refreshed) – fujy Jul 11 '17 at 14:33
  • @fujy Thanks for your reply. I've already come across this post and tried the solution but didn't work. – mordecai Jul 11 '17 at 14:52
  • `return "viewid?faces-redirect=true";` (JSF specific) in an action method in that post is theoretically known as Post-Redirect-Get (PRG), is one of the several known design principles basically used to cancel the effect of the POST HTTP method which has been triggered previously (redirect after post). You can also use AJAX for better user experience with pages they are interacting with (the JSF component library like PrimeFaces has a built-in support for almost all components it has) or use a request based token to avoid double entries being made on the server side. – Tiny Jul 11 '17 at 15:04

0 Answers0