0

I'm using spring security for logout page. when user access and view product detail page, user continues to click logout, and then it will redirect to home page, it work fine !
this is my code:

@RequestMapping(value="/logout", method = RequestMethod.GET)
public String logoutPage (HttpServletRequest request, HttpServletResponse response) {
    Authentication auth = SecurityContextHolder.getContext().getAuthentication();
    if (auth != null){    
        new SecurityContextLogoutHandler().logout(request, response, auth);
    }

    return "redirect:/homepage";
}

However I want when user logout, user still access current page(product detail page) and no need it redirect to homepage

How to fix the problem ? Thank so much !

Khanh Luong Van
  • 476
  • 3
  • 14
  • 31

1 Answers1

0

Try to get the referrer of the logout request and use it in your return redirect statement.

String referrer = request.getHeader("referer");
return "redirect:" + referrer

Here are some implementations to get the referrer: Get Referer URL in Spring MVC

Kloker
  • 499
  • 4
  • 14