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");