Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Spring MVC, does using 'redirect:process' or 'redirect:/process' differ regarding causing a lost session or session value?

I am experiencing strange behavior in my Spring MVC 3.2 application, and I noticed that this only happening when the redirect is done in an alternate way; so my questions are:

  1. Is doing 'redirect:/process' any different from 'redirect:process' for redirecting to an internal controller ?

    Does the added slash make any difference, such as affecting session handling ?

  2. What are the reasons for a lost session (or lost session attributes) ?

    There's a value I read through my application; even thou I do redirects in many cases, when I add a slash before the Controller URI, on production I am sometimes losing this value.

    Any clue on how to troubleshoot the lost session value ?

Note: I am using methods httpRequest.getSession().setAttribute and httpSession.getAttribute for accessing the session.

like image 606
abdelrahman-sinno Avatar asked Oct 20 '15 11:10

abdelrahman-sinno


People also ask

What is the use of redirect in Spring MVC?

Using the redirect prefix in your controller will generate a HTTP response with the 302 status code and the location header pointing to the redirection URL. The browser will then redirect to that URL (model exposed in the first request will be lost, and the browser URL will be the second one). Save this answer.

What is the difference between forward and redirect in Spring MVC?

Forward: is faster, the client browser is not involved, the browser displays the original URL, the request is transfered do the forwarded URL. Redirect: is slower, the client browser is involved, the browser displays the redirected URL, it creates a new request to the redirected URL.

Which of the following statements about front controller in Spring MVC is true?

Answer: Front Controller is responsible to handle the entire incoming request of an application. In Spring MVC, dispatcher servlet acts as a front controller and handles the entire incoming requests.

What object will spring use behind the scenes to issue a redirect command?

Behind the scenes, RedirectView will trigger an HttpServletResponse. sendRedirect(), which will perform the actual redirect.


1 Answers

with '/' you are declaring a path from root, which is your servlet context path. without '/', usually it's going to a path relative to your current sub path. for example, if you are at '/go/url', your are pointing to '/go/url/next', not '/next'.

I didn't check spring source code but that's how it works in web browser usually.

EDIT:

I'm sorry, in Spring MVC, you must always provide full path, not just relative path. So you should do "redirect:/full/path".

like image 145
PeiSong Xiong Avatar answered Oct 05 '22 22:10

PeiSong Xiong