Java Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesJava Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old May 27th, 2003, 09:10 AM
vrtata vrtata is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2003
Location: Hyderabad, India
Posts: 19 vrtata User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 54 m 26 sec
Reputation Power: 0
Unhappy Problems with sessions

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
Attached Files
File Type: java plogin.java (2.7 KB, 247 views)

Reply With Quote
  #2  
Old May 27th, 2003, 09:43 AM
Nemi Nemi is offline
Clueless llama
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Feb 2001
Location: Lincoln, NE. USA
Posts: 2,353 Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 2 Days 12 h 35 m 19 sec
Reputation Power: 111
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.

Reply With Quote
  #3  
Old May 27th, 2003, 11:54 PM
vrtata vrtata is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2003
Location: Hyderabad, India
Posts: 19 vrtata User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 54 m 26 sec
Reputation Power: 0
Thumbs up

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

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesJava Help > Problems with sessions


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT