This week's book giveaways are in the AI and JavaScript forums.
We're giving away four copies each of GANs in Action and WebAssembly in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of GANs in ActionE this week in the AI forum
or WebAssembly in Action in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
Sheriffs:
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Joe Ess
  • salvin francis
  • fred rosenberger

Passing value from one servlet to another

 
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
 
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)
 
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.
 
Ranch Hand
Posts: 3850
  • 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
 
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
 
But how did the elephant get like that? What did you do? I think all we can do now is read this tiny ad:
Sauce Labs - World's Largest Continuous Testing Cloud for Websites and Mobile Apps
https://coderanch.com/t/722574/Sauce-Labs-World-Largest-Continuous
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!