如何使用会话将字符串值从一个 servlet 传递到另一个 servlet?
How to pass a String value from one servlet to another servlet using session?
请检查这个问题的答案,我找到了这个:enter link description here
我如何使用会话来做到这一点:
request.setAttribute("attributeName",yourStringVAlue);
RequestDispatcher rd = request.getRequestDispatcher("yourServletPattern");
rd.forward(request,response);
并检索:
String someName = (String)request.getAttribute("attributeName");
您说 "using session"。
设置变量:
HttpSession session = request.getSession();
session.setAttribute("myId","myVariable");
检索变量:
HttpSession session = request.getSession();
String var = (String) session.getAttribute("myId");
请检查这个问题的答案,我找到了这个:enter link description here
我如何使用会话来做到这一点:
request.setAttribute("attributeName",yourStringVAlue);
RequestDispatcher rd = request.getRequestDispatcher("yourServletPattern");
rd.forward(request,response);
并检索:
String someName = (String)request.getAttribute("attributeName");
您说 "using session"。
设置变量:
HttpSession session = request.getSession();
session.setAttribute("myId","myVariable");
检索变量:
HttpSession session = request.getSession();
String var = (String) session.getAttribute("myId");