In Spring MVC, does the use of 'redirect: process' or 'redirect: / process' be used depending on the reason for the loss of the session or session?

I experience strange behavior in my Spring MVC 3.2 application, and I noticed that this only happens when the redirect is done in an alternative way; so my questions are:

  • Does ' redirect: / process ' do anything other than ' redirect: process ' to redirect to the internal controller?

    Is added slash used, for example, affecting session processing?

  • What are the causes of a lost session (or lost session attributes)?

    Here is the meaning I read in my application; even in many cases I redirect when I add a slash to the controller URI, in production I sometimes lose this value.

    Any hint on how to fix a lost session value?

Note. I am using httpRequest.getSession().setAttribute and httpSession.getAttribute to access the session.

+6
source share
3 answers

with '/' you declare a path from root, which is your servlet context context. without '/', usually this is the path to your current subpath. for example, if you are in '/ go / url', you specify '/ go / url / next' and not '/ next'.

I did not check the source code for spring, but as usual it works in a web browser.

EDIT:

Sorry, in spring MVC you should always provide the full path, not just the relative path. Therefore you should do "redirect: / full / path".

+1
source

Just a note: / - slash, backslash \ .

Except for external reasons due to other errors, neither redirect:process not redirect:/process should change anything when it comes to the session.

But these 2 redirects should not do the same if you are not on the root application page. Assuming your application runs on HTTP port 80 on server.domain server, with the myapp servlet context, and processes the http://server.domain/myapp/local/part , redirect:process requests the http://server.domain/myapp/local/part/process request from the browser http://server.domain/myapp/local/part/process when redirect:/process will ask the browser to request http://server.domain/myapp/process .

What happens next depends on your comparisons with the controller.

0
source

You probably want to analyze what causes the lost session attributes. One approach is to implement your own HttpSessionAttributeListener and log in to the public void attributeRemoved(HttpSessionBindingEvent event) . Also support for debugging.

0
source

All Articles