Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


How do you pass the data from one servlet to another
servlet?

Answers were Sorted based on User's Feedback



How do you pass the data from one servlet to another servlet?..

Answer / harish

Using Request Dispatcher, you can send the values and
forward to another page.
ServletContext.getRequestDispatcher();
reqDispatcher.forward(req,res)
Forwards a request from a servlet to another resource
(servlet, JSP file, or HTML file) on the server.
reqDispatcher.include(req,res)
Includes the content of a resource (servlet, JSP page, HTML
file) in the response.

Is This Answer Correct ?    80 Yes 22 No

How do you pass the data from one servlet to another servlet?..

Answer / debojit

First of all u have to set the value by setAttribute()
method such as:
request.setAttribute("variableName",object);

Then u have to forward that request to other servlet by
using that procedure,

ServletContext con=request.getServletContext();
RequestDispatcher rd=con.getRequestDispatcher("/servlet");
rd.forward(request,response);

U can get that information from that servlet by using the
method::
getAttribute("variableName");

Is This Answer Correct ?    50 Yes 20 No

How do you pass the data from one servlet to another servlet?..

Answer / kuru

for example if you want to pass your name from one servlet
to another,

in fiest servlet file....

String name = "Tom"
request.setAttribute("name",name);

RequestDispatcher dis = request.getRequestDispatcher
("Servlet2");

request.Forward(request,response);



in second servlet file....

request.getAttribute("name");
//this line will display "Tom"

Is This Answer Correct ?    46 Yes 20 No

How do you pass the data from one servlet to another servlet?..

Answer / tulasi vani

We can pass the data from one servlet to another using
RequestDispatcher object.


1.RequestDispatcher rd=getServletContext.getNamedDispatcher
("...");
rd.forward(request,response);

... means use the name of the url-patterns you have
specified for the servlet in web.xml.

Is This Answer Correct ?    34 Yes 15 No

How do you pass the data from one servlet to another servlet?..

Answer / vinod muda

In First Servlet i.e Test

String name = "Vinod";
request.setAttribute("name",name);
RequestDispatcher dis = request.getRequestDispatcher
("Test2");
dis.forward(request, response);
---------------------------------------
Now in Second Servlet i.e Test2

String name = (String) request.getAttribute("name");

Is This Answer Correct ?    29 Yes 10 No

How do you pass the data from one servlet to another servlet?..

Answer / debojit

First of all u have to set the value by setAttribute()
method such as:
getServletContext().setAttribute("variableName",object);

Then u have to forward that request to other servlet by
using that procedure,


RequestDispatcher rd=getServletContext
().getRequestDispatcher("/servlet");
rd.forward(request,response);

U can get that information from that servlet by using the
method::
getServletContext().getAttribute("variableName");

Is This Answer Correct ?    23 Yes 10 No

How do you pass the data from one servlet to another servlet?..

Answer / abilash

also we can set data in the request too

request.setAttribute("variableName"object);

we can get the value in the next servlet by

Object obj = request.getAttribute("variableName");

Is This Answer Correct ?    24 Yes 18 No

How do you pass the data from one servlet to another servlet?..

Answer / trupti

Using Request Dispather

Is This Answer Correct ?    6 Yes 4 No

How do you pass the data from one servlet to another servlet?..

Answer / rams

can any one post the structure of the webapps folder?? i created a login servlet n redirect servlet,i've sent values from login to redirect...can any one post the structure?? its showing an error like,redirect is not found...pls help me

Is This Answer Correct ?    1 Yes 2 No

How do you pass the data from one servlet to another servlet?..

Answer / tushar

these above solution transfer the content from servlet1 to servlet2, but what if we want to do some other processing after it.

Is This Answer Correct ?    3 Yes 7 No

Post New Answer

More Servlets Interview Questions

What is the use of servletconfig interface?

0 Answers  


Define servlet mapping?

0 Answers  


What is the difference between Difference between doGet() and doPost()?

0 Answers  


How many ways to remove the session object in the container

6 Answers   Bosch,


What is done after deploying a war file and before client gives a request

2 Answers   Bosch,


When servlet is loaded?

0 Answers  


what is the difference between Servlet and JSP?Advantage of JSP over Servelt?Any concept present in JSP which we cant implement in Servlet?

31 Answers   ABC, Apere, AZTEC, CTS, CybAge, iFlex, Impact Systems, Sara, TCS,


Explain the different ways for servlet authentication?

0 Answers  


How can the referrer and the target urls be used in servlet?

0 Answers  


What are some disadvantages of storing session state in cookies?

0 Answers  


Explain how does JSP handle run-time exceptions?

0 Answers   BirlaSoft,


What is a web container and what is its responsibility?

0 Answers  


Categories