首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

Struts2.x快速下手3-使用Servlet API添加状态跟踪(HttpSession)

2012-11-13 
Struts2.x快速上手3--使用Servlet API添加状态跟踪(HttpSession)1)在LogonAction的execute方法添加:??? Ac

Struts2.x快速上手3--使用Servlet API添加状态跟踪(HttpSession)

1)在LogonAction的execute方法添加:
??? ActionContext.getContext().getSession().put("username", getUsername());


??? ActionContext
???? ?+getSession()
?? ?注意:返回的不是HttpSession,而是一个Map的封装,
??????????? ?Struts2.x框架的内置拦截器实现了Session和HttpSession之间的转换

??? 如:

??? Map userlist = (Map) ActionContext.getContext().get("session").put("username",getUsername());

?

2)在目标页面successful.jsp添加
???${username }

?? 输出该Session中key为"username"的值

热点排行