当前位置: 技术问答>java相关
java读取session变量问题----在线等待
来源: 互联网 发布时间:2015-08-23
本文导语: servlet如何去读取页面中的session变量?请大虾指点。 | HttpSession session=request.getSession(false); String paramValue = session.getAttribute(paramName); | import javax.servlet.http.*; import javax.servlet....
servlet如何去读取页面中的session变量?请大虾指点。
|
HttpSession session=request.getSession(false);
String paramValue = session.getAttribute(paramName);
String paramValue = session.getAttribute(paramName);
|
import javax.servlet.http.*;
import javax.servlet.*;
public class check extends HttpServlet{
public check(){
super();
}
public void doGet(HttpServletRequestrequest,HttpServletResponse response) throws ServletException, java.io.IOException{
HttpSession session=request.getSession(false);
String ss = (String)session.getAttribute("Check_User");
}
}
import javax.servlet.*;
public class check extends HttpServlet{
public check(){
super();
}
public void doGet(HttpServletRequestrequest,HttpServletResponse response) throws ServletException, java.io.IOException{
HttpSession session=request.getSession(false);
String ss = (String)session.getAttribute("Check_User");
}
}
|
设置session:request.getSession().setAttribute("name",name);
取session:request.getSession().getAttribute("name");
其中request为HttpServletRequest类型
取session:request.getSession().getAttribute("name");
其中request为HttpServletRequest类型
|
如果form传递类型是post则在servlet的doPost方法里写
public void doPost (HttpServletRequest req, HttpServletResponse res)
{HttpSession session=res.getSession(false);
String paramValue = session.getAttribute(paramName);
}
如果是get就在doGet里写
public void doPost (HttpServletRequest req, HttpServletResponse res)
{HttpSession session=res.getSession(false);
String paramValue = session.getAttribute(paramName);
}
如果是get就在doGet里写