|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
I am new to development in JSP/Servlets. I am trying to develop a simple login authorization system using sevlets. For this I am using a simple html based logon form. On submit i am invoking a servlet which does the authentication and creates a session.
HttpSession session = request.getSession(false); session.setAttribute("fusion.user", uName); session.setAttribute("fusion.auth", "Y"); String eURL = response.encodeRedirectURL(tURL); response.sendRedirect(eURL); The problem is I am unable to retrieve the session variable set in the servlet in the subsequent redirected jsp page. The session variables are showing as NULL. <% session = request.getSession(false); String name = (String) session.getAttribute("fusion.user"); String authe = (String) session.getAttribute("fusion.auth"); out.print("<BR>"); out.print(name); out.print("<BR>"); out.print(authe); %> Could somebody help me on this. I am enclosing the servlet code along with this message. Thanx in advance Ramesh |
|
#2
|
|||
|
|||
|
First of all, I don't think you want to use the boolean form of the getSession in your servlet. Sending flase to that method will NOT return a session if one has not been created already. If this is a user first logging in they probably won't have a session already. Try this instead
Code:
HttpSession session = request.getSession(); Secondly, the "session" variable is already available in a jsp. It is implicitly available to all jsp's unless you specify that it should not be. You are overwriting the implicit variable when calling Code:
session = request.getSession(false); in you jsp. Delete that line and see what happens Code:
<%
String name = (String) session.getAttribute("fusion.user");
String authe = (String) session.getAttribute("fusion.auth");
out.print("<BR>");
out.print(name);
out.print("<BR>");
out.print(authe);
%>
Lastly, you don't show the url you request and the url you redirect to. If the browser does not think they are the exact same host it will not send the cookie for the session. |
|
#3
|
|||
|
|||
|
Thanx Nemi.. It works now. The problem was a combination of the boolean type of getSession and that I was passing the complete URL in the sendRedirect instead of the absolute path.
Thanx once again. Ramesh ![]() |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Java Help > Problems with sessions |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|