在struts
要獲得上述對象
ActionContext ctx = ActionContext
Map session = ctx
細心的朋友可以發現這裡的session是個map對象在Struts
另外
HttpServletRequest request = ServletActionContext
HttpServletResponse response = ServletActionContext
HttpSession session = request
如果你只是想訪問session的屬性(Attribute)
要使用IoC方式
publicclass IoCServlet extends ActionSupport implements SessionAware
private String message;
private Map att;
private HttpServletRequest request;
private HttpServletResponse response;
public String getMessage() {
return message;
}
publicvoid setSession(Map att) {
this
}
publicvoid setServletRequest(HttpServletRequest request) {
this
}
publicvoid setServletResponse(HttpServletResponse response) {
this
}
@Override
public String execute() {
att
HttpSession session = request
StringBuffer sb =new StringBuffer(
sb
sb
Response Buffer Size:
sb
sb
Session ID:
sb
message = sb
return SUCCESS;
}
}
在struts
<interceptor
From:http://tw.wingwit.com/Article/program/Java/ky/201311/28124.html