ITeye博客

Struts 2 中Session的用法

guanjh · 2007-12-30 18:02 · CSS · Struts · JSP · Markdown

在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><s:if color="#cc0000" test<font="">
<jsp:forward page="/pages/uiTags/Login.jsp"></jsp:forward>
</s:if>

评论(1)

  1. #1 楼 · elf8848 · 2008-07-31 09:51

    Map session ? 为什么 是Map 类型地, 不是HttpSession

评论功能维护中,当前仅展示历史评论。