简体   繁体   中英

How to pass a String value from one servlet to another servlet using session?

Please i cheked for the answer of this question and i found this one : enter link description here

how can i do that using session:

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

and to retrieve :

String someName = (String)request.getAttribute("attributeName");

You stated "using session".

Set variable:

HttpSession session = request.getSession();
session.setAttribute("myId","myVariable");

Retrieve variable:

HttpSession session = request.getSession();
String var = (String) session.getAttribute("myId");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM