File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Life cycle fo session attributes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Life cycle fo session attributes" Watch "Life cycle fo session attributes" New topic

Life cycle fo session attributes

sruthi reddy
Ranch Hand

Joined: Aug 03, 2008
Posts: 34
I am using session atttibutes to know whether a user is loged in or not.Basically what i am doing is i am authenticating user with database and if user's username and password are correct, then in the sevlet i am setting a string to yes value and checking that condition where ever required in the application.But in some pages of application, i have a link which will call my main page.If user is loged in then, my main page should have user details but its not happening. my session attributes are not available in main page. Can anyone suggest me what to do.
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63865

What is happening?
[ August 08, 2008: Message edited by: Bear Bibeault ]

[Asking smart questions] [About Bear] [Books by Bear]
sruthi reddy
Ranch Hand

Joined: Aug 03, 2008
Posts: 34
i am setting session attributes like this

request.getSession().setAttribute("usName", usrName);
request.getSession().setAttribute("isLoggedIn", testLogin);

and i am able to get back those values in CalenderDisplay.jsp (my main page) but when i am trying to get attributes from other pages, i am getting null value.
Deepak Bala

Joined: Feb 24, 2006
Posts: 6662

Perhaps you are attempting to retrieve it with the wrong keys ? Why dont you try printing all the keys and values in the session attribute scope ? You can also register some listeners in case you want to be notified when a session object is added or removed or replaced. This way any change in these values will be visible to you via debug statements.

SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13037
I am trying to get attributes from other pages, i am getting null value.

Are all of these pages in the same web application? Show us the URLs by which these pages are reached.

I agree. Here's the link:
subject: Life cycle fo session attributes
jQuery in Action, 3rd edition