简体   繁体   English

如何使用会话将字符串值从一个servlet传递到另一个servlet?

[英]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 请我为这个问题的答案che之以鼻,我找到了这个问题: 在此处输入链接说明

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");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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