1

In my spring project i have solved the backbutton issue using the below interceptor.

public class SampleInterceptor implements HandlerInterceptor
{
    public SampleInterceptor() {

    }

    @Override
    public void afterCompletion(HttpServletRequest arg0,
            HttpServletResponse arg1, Object arg2, Exception arg3)
            throws Exception {


    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response,
            Object object, ModelAndView model) throws Exception {


        if(request.getMethod().equals("GET"))
        {
            response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1.
            response.setHeader("Pragma", "no-cache"); // HTTP 1.0.
            response.setDateHeader("Expires", 0);
        }
        else if(request.getMethod().equals("POST"))
        {
            System.out.println("After post request : ");
        }

    }

}

I have cleared the browser cache for all request except post.Now user logged out and click back it does not go to the application only for get request.but post request it goes to the application.how to i avoid that problem in post request.If i cleared the browser cache for post request it asks confirm form submission.how to solve this issue? Any help will be greatly appreciated!!

Selva
  • 1,620
  • 3
  • 33
  • 63

2 Answers2

0

It can be avoid by using AJAX instead of form submission. use AJAX POST to submit your request.

Also please refer below urls for more details: 1. Prevent Back button from showing POST confirmation alert

  1. http://en.wikipedia.org/wiki/Post/Redirect/Get

Thanks!!!

Community
  • 1
  • 1
Subbu
  • 308
  • 2
  • 4
  • 12
0

Post will always ask for form submission.

Either post your data using AJAX post and then redirect on receipt on response or submit your data constructing a get request.

Be aware than when a person does back on pages that update or insert data. The data is re-posted to server and could lead to duplicate insert / updates. Do handle such cases if you intend to.

Godwin
  • 512
  • 4
  • 14