<p>!_NEWLINE_!Passing a parameter from one servlet to another
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Jayashree_Gopal
Posted On:   Monday, December 17, 2001 01:25 AM

I am writing a servlet which verifies the username and password before it connects a user to a database. I want to start a session as soon as i have finished the verification. I have created a HttpSession object and used the putAttribute method to append the username and password. I have done this so tht in the subsequent pages, the username and password can be picked up from the session without prompting the user again. When i pass the session id to the next page,will the username and the password get passed automatically?? Any syntax help in this matter will be highly appreciated. Please do let me know how do i pass this session id as a parameter to the next servlet and to subsequent servlets. If the next servlet consis   More>>



I am writing a servlet which verifies the username and password before it connects a user to a database. I want to start a session as soon as i have finished the verification. I have created a HttpSession object and used the putAttribute method to append the username and password. I have done this so tht in the subsequent pages, the username and password can be picked up from the session without prompting the user again. When i pass the session id to the next page,will the username and the password get passed automatically??

Any syntax help in this matter will be highly appreciated.

Please do let me know how do i pass this session id as a parameter to the next servlet and to subsequent servlets.
If the next servlet consists of hyperlinks,can i pass this session id as a parameter to the links too!!!

Thanks for everything!!!
Jayashree

   <<Less

Re: <p>!_NEWLINE_!Passing a parameter from one servlet to another

Posted By:   Mittal_Bhiogade  
Posted On:   Monday, December 17, 2001 01:55 AM

anything u put in session is available until your session is terminated (i.e. the browser is closed or session is invalidated)

u can put in session as follows...

HttpSession obj= req.getSession(true);
obj.putValue("usename","ABC");
obj.putValue("password","XYZ");

Now u have put the data in session in say "ServletA", this data can be "get" in any of the subsequent servlets or jsp as follows,

HttpSession obj= req.getSession(true);
String strUserName=(String)obj.getValue("usename");
String strPassword=(String)obj.getValue("password");

Hope this helps...
About | Sitemap | Contact