my dog learned polymorphism*
The moose likes Servlets and the fly likes Pls...Anybody help me...asap Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Pls...Anybody help me...asap" Watch "Pls...Anybody help me...asap" New topic
Author

Pls...Anybody help me...asap

Raukutam Sandeep
Ranch Hand

Joined: Nov 15, 2000
Posts: 61
hi everybody,

i'm developing an Intranet mailing system using JSP.
I want use the userid throughout my session.
For that, i'm using the implicit 'session' object in JSP, as shown below..
String usrname=request.getParameter("username");
if(session.isNew())
session.putValue("Username",usrname);
I'm writing this code in a file, say login.jsp
I want to use that 'usrname' throughout my session, until session is invalidated.
In another file, say inbox.jsp i want to use that userid.
For that i'm retrieving the value stored in the session as follows..
String userid=(String)session.getValue("Username");
out.println("<b>"+userid+"</b>");
But i'm getting a null value when I use the above statement. Instead I should get the userid that is entered by the user during login....
Why Am I getting a null value, where in I should get the username?
Pls tell me where did I go wrong..
Reply asap..
Waiting for the help..
regds,
Sandeep.
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
Did you create the session first by sending true to the constructor?
Bosun

Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
Raukutam Sandeep
Ranch Hand

Joined: Nov 15, 2000
Posts: 61
hi,

is this the correct way of passing true to the constructor?
session=request.getSession(true);
If it is wrong pls tell me the correct way..
And did I go wrong in the code in my previous query..
Pls reply asap..
regds,
Sandeep.
Raukutam Sandeep
Ranch Hand

Joined: Nov 15, 2000
Posts: 61
hi,

is this the correct way of passing true to the constructor?
session=request.getSession(true);
If it is wrong pls tell me the correct way..
And did I go wrong in the code in my previous query..
Pls reply asap..
regds,
Sandeep.
Jason Allen
Greenhorn

Joined: Jan 25, 2001
Posts: 26
Is the file login.jsp the form where the user enters their userid? If so, I don't think the getParameter will return anything, because it is actually running before the user has input any value.
I have my login setup like this.
login.jsp - screen to capture login info, once they hit login button, I send them to menu.jsp
menu.jsp - screen to getParamater from login.jsp and validate the user info. if they are not validated, I send them back to login.jsp. If they are validated, it then store the info in a session variable using the session.setAttribute.
It should then be available until the session ends.
Good luck!
Jason.
Raukutam Sandeep
Ranch Hand

Joined: Nov 15, 2000
Posts: 61
hi everybody,

sorry, for the trouble I gave u.
The session is working fine now and I'm able to retrieve the username throughout the session.
Thanx again,
Sandeep.
 
 
subject: Pls...Anybody help me...asap
 
Similar Threads
with out authentication it is forwading to another page
Need help with small problems
servlet exception error in my code(urgent)
Problem with jsp:useBean tag...URGENT
Problem in <many-to-one> relationship