0

I captured an URL:(example)

https://lol.com/question2

In a variable in my .jsp, then I have to log in and in the back, after validating that the login was correct, I'm redirecting the page to the home of my application but what I want is to redirect it the URL that I captured before login in. Is there a way to capture that variable in the back when its about to redirect? Like calling a function in front from the back so that it returns the URL?

This is the function from where I redirect:

protected void handle(HttpServletRequest request, 
  HttpServletResponse response, Authentication authentication) throws IOException {
    var urlNew = functionToCaptureURL();

    redirectStrategy.sendRedirect(urlNew);
    //redirectStrategy.sendRedirect("https://lol.com/home");
}
  • Jose Maria Sosa Gomez - If one of the answers resolved your issue, you can help the community by marking it as accepted. An accepted answer helps future visitors use the solution confidently. Check https://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work to learn how to do it. – Arvind Kumar Avinash May 14 '20 at 12:28

2 Answers2

1

Use RequestDispatcher::forward instead of sendRedirect. Check Difference between JSP forward and redirect to learn more about it.

Arvind Kumar Avinash
  • 71,965
  • 6
  • 74
  • 110
0

Please before send login request fill referer header by your captured url, then create a class which extends the SimpleUrlAuthenticationSuccessHandler class and call setUseReferer(true) on overriden method RefererRedirectionAuthenticationSuccessHandler(). for more info check this link: https://www.baeldung.com/spring_redirect_after_login