java中session的使用

1、创建session:

ActionContext actionContext = ActionContext.getContext();
Map<String, Object> mapSession = actionContext.getSession();
mapSession.put("branch", branch);
mapSession.put("permission", per);

2、jsp读取session

if(session.getAttribute("branch") == null||session.getAttribute("permission") == null)
	{
		response.setCharacterEncoding("utf-8");
		out.print("<script>alert('您还没有登录,请登录') </script>");
		out.flush();
		out.close();
	}

3、java后台读取session的值

ActionContext actionContext = ActionContext.getContext();
Map session = actionContext.getSession();
String inputUserid =(String)session.get("username");
String proving =(String)session.get("proving");

 

posted @ 2019-02-21 09:43  狗蛋哥  阅读(9506)  评论(0)    收藏  举报