• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Passing value from one servlet to another

 
Swetha Mohan
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello friends
I have two servlets
[login servlet]
I am new to servlet programming.I am working on a simple login page.As soon as the user name and password are entered the login servlet goes and checks in the database and redirects to the next page once the username and password is correct.
[entry servlet]
In the next page the user is asked to enter his/her name and address.on clicking the save button on this page the values name and address along with the login name (the name which he used to login) should be added on to the database.
Now please tell me how to retrive the login name from the first page to this second page.
how can we pass the value form [login servlet] to [entry servlet]?
Please help

Thanks in advance
Swetha
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are many ways.

- URL re-writing
- store login name to your request object and get that in your second page in a hidden field
- you can go for use session (not the best choice in your case)
 
Himanshu Bisht
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Well you have many ways to do this.

a) You can get the value in second servlet by requesting the parameter.

String username=request.getParameter("name");

b) You can put the username in session and then retrieve it anywhere in your application.

c) You can pass the username in queryString and then retrieve it in second servlet.

there are other was also like setting it in cookies, taking hidden fields (in JSP) but I am sure one of the above methods will fullfill your requirement.

thanks

[ December 28, 2005: Message edited by: Himanshu Bisht ]
[ December 28, 2005: Message edited by: Himanshu Bisht ]
 
Swetha Mohan
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello

Can you please explain the three methods briefly.
 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Swetha Mohan:
Hello

Can you please explain the three methods briefly.



Do this for now...


Write this code in LoginServlet


Write this code in nextPage.jsp



Hope it helps.
 
Swetha Mohan
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello rathi

The session method worked...

Thankyou for that
 
Tirupathi Rao Chukka
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wishing you and your families a Happy And a Prosporous New Year 2006 for all Javaranch members
 
Tirupathi Rao Chukka
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you want to mentain the objects through your applications means u need to follow the any one of the technique

You can do it by storing object in requset (ServletRequest)

setAttribute(key,value); now you can get this object by using the following method getAttribute(key);

or you can store it in the session same methods are also availabe.

you need to read the session tracking 4 mechanisims that will help you lot
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic