Struts 2 中Session的用法

Struts 2 中Session的用法

在ActionSupport子类的execute方法中存储session
Map session = ActionContext.getContext().getSession();
session.put("logged-in","true");

 

同样在execute方法中,可以清除session变量
Map session = ActionContext.getContext().getSession();
session.remove("logged-in");

 

在jsp的head部分引入css文件
<head>
     <link href="<s:url value="/css/main.css"/>" rel="stylesheet" type="text/css"/> 
</head>

在jsp访问session
session Time: </b><%=new Date(session.getLastAccessedTime())%>

<a href="<%= request.getContextPath() %>/roseindia/logout.action">Logout</a>

 jsp中使用struts-tag访问session变量
<s:if test="#session.login != 'admin'">
 <jsp:forward page="/pages/uiTags/Login.jsp" /> 
</s:if>

你可能感兴趣的:(Struts 2 中Session的用法)