Announcement Announcement Module
No announcement yet.
How to get the source of a redirect ? Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to get the source of a redirect ?

    Hi all,

    I'm using a simple login approach in a web application.
    When the user's session isn't validated, we redirect him to a login page.
    For example:
    return new ModelAndView(new RedirectView("login.htm"));
    This works fine, but after the user logs in on login.htm he gets forwared to the main page.
    Is there a way to find out from where the user was redirected ? So we can redirect the user to his original request.

    I know it's possible to just store the source of the redirect somewhere and then retrieve this location after logging in.
    But I was wondering if there was a more elegant approach to this.

  • #2
    Depending on the web container that you're using, it may be simpler to let the container do this for you.

    I know that Tomcat handles this very cleanly.
    Say, for example, that you're on an arbitrary page of your application and you go away for long enough for the session to timeout - you return to your desk and click on a link or submit some data and Tomcat sees that you're not logged in anymore so it presents you with the login screen and (when you've provided username and password) directs you to the correct screen.

    Check out the Tomcat docs for more info...
    Tomcat security realms
    ..the page is quite long but the main point is quite short, with most of the content being related to the various ways of specifying the usernames/passwords.

    It's a long time since I used Weblogic or any other containers, so I can't be sure about these - but it's highly likely that they provide similar functionality.