struts

struts2获取request 的三中方法浅谈

建议通过ServletRequestAware 通过IOC注入request。

1.通过Map方式

Map request =(Map) ActionContext.getContext().get("request");

List list =service.find();

request.put("list",list);

2.通过ServletActionContext

HttpServletActionRequest request = ServletActionContext.getRequest();

request.setAttribute("username","aaa");

<s:property value="#request.username"/>

3.通过ServletRequestAware 注入request

private HttpServletRequest request;

private HttpServletResponse response;

//生成getter setter  方法

public String execute(){

request.setAttribute("username","bb");

}

 

 

 

你可能感兴趣的:(struts)