水仁博客

上善若水,仁恕载物
随笔 - 11, 文章 - 0, 评论 - 4, 引用 - 0
数据加载中……

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>

posted on 2007-12-30 18:02 水仁圭 阅读(5618) 评论(3)  编辑  收藏

评论

# re: Struts 2 中Session的用法  回复  更多评论   

请问<s:if test="#session.login != 'admin'">中的session.login 是什么时候定义的?
2008-08-12 12:41 | 游客

# re: Struts 2 中Session的用法  回复  更多评论   

看不懂啊!!!!
2014-04-13 20:17 | wn

# re: Struts 2 中Session的用法  回复  更多评论   

详细一点啊~~~~
2014-04-13 20:18 | wn

只有注册用户登录后才能发表评论。


网站导航: