struts2中获取session,request有几种方式
1个回答
2016-07-08
展开全部
aware接口注入,即实现ServletRequestAware接口(此方式最为麻烦)
public class Demo2ServletAction extends ActionSupport implements ServletRequestAware{
private HttpServletRequest request;
@Override
public String execute() throws Exception {
request.setAttribute("gf", "request_aware");
return SUCCESS;
}
@Override
public void setServletRequest(HttpServletRequest request) {
this.request = request;
}
}
public class Demo2ServletAction extends ActionSupport implements ServletRequestAware{
private HttpServletRequest request;
@Override
public String execute() throws Exception {
request.setAttribute("gf", "request_aware");
return SUCCESS;
}
@Override
public void setServletRequest(HttpServletRequest request) {
this.request = request;
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询