Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass a String value from one servlet to another servlet? [duplicate]

Tags:

java

jsp

servlets

I have one jsp from which I am getting a string value in servlet1 using 'request.getParameter' I want to link servlet1 and servlet2 and send the string value which i have got in servlet1 to servlet2.

please help.

Many thanks in advance.

like image 332
mujib009 Avatar asked Oct 20 '25 16:10

mujib009


2 Answers

You need to set request attribute

In your servlet1.

request.setAttribute("attributeName",yourStringVAlue);
RequestDispatcher rd = request.getRequestDispatcher("yourServletPattern");
rd.forward(request,response);

In your Servlet2

String someName = (String)request.getAttribute("attributeName");
like image 99
Prasad Kharkar Avatar answered Oct 23 '25 07:10

Prasad Kharkar


In Servlet 1 :

request.setAttribute("myAwesomeAttributeName",myAwesomeAttributeValue);

then recieve it in servlet 2 by

request.getAttribute("myAwesomeAttributeName");
like image 31
Hussain Akhtar Wahid 'Ghouri' Avatar answered Oct 23 '25 05:10

Hussain Akhtar Wahid 'Ghouri'



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!