我的应用程序中有两个servlet。第一个servlet包含post
方法,第二个servlet包含get
方法。第一个servlet将用户名传递给第二个servlet。我正在使用httpsession
来传递对象。当我从电脑上的Postman应用程序调用时,一切正常,但是当我从android应用程序调用时,它显示为null对象。
这是我的代码: 第一个servlet:
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
String userName,password;
userName=request.getParameter("userName").toString();
password=request.getParameter("password").toString
HttpSession session = request.getSession();
session.setAttribute("userId",userName);
RequestDispatcher rd=request.getRequestDispatcher("/another servlet");
rd.forward(request,response);
}
第二个Servlet:
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
GetUserTran cp = new GetUserTran();
//cp.setBoId((String)request.getAttribute("boId"));
HttpSession session = request.getSession();
String urname = (String) session.getAttribute("userId");
System.out.println(urname);
}