我正在尝试将会话值设置如下:
if (request.getParameter("page") != null) {
page = Integer.parseInt(request.getParameter("page").toString());
}
if (request.getParameter("se_tempcardnumber") != null) {
tempcardnumber = request.getParameter("se_tempcardnumber").toString();
session.setAttribute("session_tempcardnumber", tempcardnumber);
}
if (request.getParameter("se_empid") != null) {
empid = request.getParameter("se_empid").toString();
session.setAttribute("session_empid", empid);
}
if (request.getParameter("se_issuedate") != null) {
issuedate = request.getParameter("se_issuedate").toString();
session.setAttribute("session_issuedate",issuedate);
}
if (request.getParameter("se_cardstatus") != null) {
cardstatus = request.getParameter("se_cardstatus").toString();
session.setAttribute("session_cardstatus", cardstatus);
}
我尝试按如下方式访问会话值:
if(session.getAttribute("session_empid")!=null) {
session_empid =(String)session.getAttribute("session_empid");
}
if(session.getAttribute("session_tempcardnumber")!=null) {
session_tempcardnumber =(String)session.getAttribute("session_tempcardnumber");
}
if(session.getAttribute("session_issuedate")!=null) {
session_issuedate =(String)session.getAttribute("session_issuedate");
}
if(session.getAttribute("session_cardstatus")!=null) {
session_cardstatus =(String)session.getAttribute("session_cardstatus");
System.out.println("session_cardstatus : "+session_cardstatus);
}
为了测试目的,我单独设置了
System.out.println("session_cardstatus : "+session_cardstatus);
的值,并且打印了相同的内容。它是第一次打印,但是到第二次时,该值是空的,尽管我在会话中未删除任何设置的变量。
请告诉我怎么做;
谢谢并恭祝安康
最佳答案
检查在将值设置为会话之前生成的会话ID
request.getRequestedSessionId()或session.getId()