I am trying to retrieve session variables that were stored by a servlet. In the application, the servlet redirects the user to a external authentication url (eg Windows Live auth)…and before redirecting, the servlet saves some values as session variables.
After the user is authenticated at external auth url, now he is redirected to a second page of my application. This second page can be jsp or servlet..
My question is, is it possible to retrieve the session variables stored by the original servlet initially, in the second page? Will i be able to get the session variables irrespective of second page being jsp or servlet?
And if session variables stored in this manner cannot be obtained, then how do I obtain those variables (ie please suggest an alternative method)….
Yes, if the servlet that issued the session variables (unclear to me if this is the case) is in the same Web Application (WAR), you can simply retrieve the session scoped variables by calling
HttpServletRequest.getSession().getAttribute("someName");. This works in servlets as well as JSPs.BTW: This will perfectly work if you session is maintained by a cookie. If you use URL rewriting it depends on the Windows Live API, in this case Windows Live must include the session ID parameter in the query string that redirects back to your app.