| Author |
how to get the username from session?
|
sabin ran
Greenhorn
Joined: Aug 06, 2010
Posts: 22
|
|
hi, i created the http session after the username and password validation. now i want to use that username to be used in the database query to fence the data from table with that username.
i have been able to display the username in the jsp page. thanks
|
 |
Chinna Eranna
Ranch Hand
Joined: Dec 08, 2009
Posts: 174
|
|
First you need to set the username in the session object as attribute after successful validation of user.
Then you can retrieve it using getAttribute.
Check this article for more details.
|
- Chinna
|
 |
sabin ran
Greenhorn
Joined: Aug 06, 2010
Posts: 22
|
|
|
thanks for reply. i have already been able to display the username in the jsp page as you have mention and the article to suggested. but the problem is little different. i have created the session during the authentication. the user gets into his home page, navigate to different jsp page(x) with link and in that X page i want to show the data fence from the database according to the username of that session.
|
 |
Chinna Eranna
Ranch Hand
Joined: Dec 08, 2009
Posts: 174
|
|
When a session is created for the user, are you storing username in the session ?
One the username is stored in the session as attribute, you can get the username from the session in any jsp/servlet, unless the session is invalid.
|
 |
sabin ran
Greenhorn
Joined: Aug 06, 2010
Posts: 22
|
|
yes.. i am storing the username in the session with
session.setAttribute("user", name) in the Authenticate.java- servlet
but i am not being able to get that username in the UserStatus.java- servlet. i have tried
String username= (String)session.getAttribute("user"); but its does not work.
what have i missed out here? please help.
|
 |
Vishal Hegde
Ranch Hand
Joined: Aug 01, 2009
Posts: 970
|
|
Click here
Me to studying servlets still stuck in response ....hope that the above link helps you out
|
http://www.lifesbizzare.blogspot.com || OCJP:81%
|
 |
Chinna Eranna
Ranch Hand
Joined: Dec 08, 2009
Posts: 174
|
|
Print Session Id in following scenarios:
just after setting the attribute in Authenticate.java servlet.
just before retrieving the attribute in UserStatus.java servlet.
Session Id can be retrieved by using session.getId().
You must see the same Id.
|
 |
 |
|
|
subject: how to get the username from session?
|
|
|