wood burning stoves 2.0*
The moose likes Servlets and the fly likes servlets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "servlets" Watch "servlets" New topic


kiruthika raghunathan

Joined: Dec 03, 2003
Posts: 9
In a servlet how to send a data which is obtained in one servlet to another one servlet?
for example:
Iam writing a servlet to input an username and in this servlet iam checking whether the length is > than zero and i donno how to pass that name to another servlet where it is checked and then dispaly some message or something
P. Udaya Shankar

Joined: Nov 18, 2003
Posts: 21
use request dispatcher to the desired servlet
catch the request do the processing
RequestDispatcher rd =null;
hope this will use for u
kiruthika raghunathan

Joined: Dec 03, 2003
Posts: 9
String username = request.getParameter("username");
if ( username != null && username.length() > 0 ) {
RequestDispatcher dispatcher =
if (dispatcher != null)
dispatcher.include(request, response);
I have done this in the first servlet i have to pass the name to another servlet and check it there
donno how to get it in that servlet?
Frank Carver

Joined: Jan 07, 1999
Posts: 6920
It may be a silly question, but why does the code which checks the username need to be a servlet? Would it not make more sense just to use a regular java class, and simply call a method, passing in the username as a parameter?

Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
try this
Praful Thakare
Ranch Hand

Joined: Feb 10, 2001
Posts: 614
Adding more to Franks post,cant it be done thru javascript?
Removing HttpR,HttpR from to Nirants post,
[ December 08, 2003: Message edited by: Praful Thakare ]

All desirable things in life are either illegal, banned, expensive or married to someone else !!!
Mike Cronin

Joined: Apr 17, 2002
Posts: 25
How about storing the username to a session variable, then retrieving that session variable in the second servlet.
Consider Paul's rocket mass heater.
subject: servlets
Similar Threads
one servlet calling another servlet
How To Use Servlet Instead Of Jsp In Struts2
how to transfer Streams from one servlet to another servlet
In how many ways we can call another servlet from the doPOST()
interservlet communication