1

I have written a custom interceptor for disabling back button functionality in browser. But code is not working. i have added meta tag in html also. I do not want to use java script for this.

public String intercept(ActionInvocation invocation) throws Exception {
                final ActionContext actionContext = invocation.getInvocationContext();
                HttpServletResponse response = (HttpServletResponse) actionContext.get(StrutsStatics.HTTP_RESPONSE);
                if(response != null){

                    response.setHeader("Cache-Control", "no-cache, no-store");
                    response.setHeader("Pragma", "no-cache");
                    response.setHeader("Expires", "-1");
                }

                return invocation.invoke();
            }

Can i write a custom interceptor which will check if user session is exists it will redirect on the same page from where user clicked browser back button.

Any suggestion how can i implement it.

Lalit Chattar
  • 1,914
  • 8
  • 27
  • 49
  • 2
    You can't disable the back button. The back button is a fundamental feature of a browser that cannot be circumvented. – Roman C Jun 27 '15 at 11:28
  • possible duplicate of [How to disable back button navigation on certain pages](http://stackoverflow.com/questions/3359941/how-to-disable-back-button-navigation-on-certain-pages) – Roman C Jun 27 '15 at 11:28
  • Generally you can't, you can do some hacks for example http://stackoverflow.com/questions/12381563/how-to-stop-browser-back-button-using-javascript but not a recommended way at all. – Alireza Fattahi Jun 27 '15 at 14:10
  • Please specify what goes wrong on your site if user clicks the back bottom. – Alireza Fattahi Jun 27 '15 at 14:11
  • http://stackoverflow.com/a/22633221/1654265 – Andrea Ligios Jun 29 '15 at 11:31
  • possible duplicate of [Why after logout clicking back button on the page displays previous page content?](http://stackoverflow.com/questions/22632794/why-after-logout-clicking-back-button-on-the-page-displays-previous-page-content) – Andrea Ligios Jun 29 '15 at 14:14

1 Answers1

0

Ok so I have found a solution which disable back button functionality.

I have created one action with name RedirectAction which checks if session is exist or not. if session exists then it redirects user on home page otherwise on login page.

<action name="home" class="com.demo.actions.RedirectAction" method="redirectAtHome">
    <result name="success">home</result>
    <result name="fail" type="redirectAction">
         <param name="actionName">welcome</param>
    </result>
</action>
Lalit Chattar
  • 1,914
  • 8
  • 27
  • 49