Disabling the back button navigation in Struts 2 without using java script

788 Views Asked by At

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.

1

There are 1 best solutions below

0
On

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>