how to remember the client's request? (URGENT HELP PLS!!)


General J2EE: how to remember the client's request? (URGENT HELP PLS!!)

  1. Hi,
    I have a few jsp pages and i track users with session variables. now if a user that has not logged in tries to do something that only the logged in ones can, i redirect them to the login.jsp and that's no problem
    but the problem is that after log-in i need to redirect the user to the page they tried to view before they were asked to log-in.
    i am fairly new to the jsp world and i need help with this.
    thank you
  2. Before you redirect the user to the login.jsp you could store the actual request in the session via the setAttribute method. Then when logged in you could get this information from the session via the getAttribute method and redirect the user to where they initially wanted to go.
  3. Hi Jack,

    saving the information needed to the session is quite the right way, but I wouldn't save the whole request! If you really just need the original URL called by the client, get this by calling getRequestURL on the request object (you may need to cast it to HttpServletRequest if it's not already). This returns a StringBuffer representing the URL the client originally called but without any parameters passed with the url. If you need saving url passed parameters as well get them by calling getQueryString, concatenate the two strings and save them to the session.
    Just saving those information to the session you need, would be a much cleaner way of programming, though the way proposed in the first answer would do as well.