读书人

Struts2.x快速下手3-使用Servlet API添

发布时间: 2012-11-13 10:00:50 作者: rapoo

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"的值

读书人网 >软件架构设计

热点推荐