例子中使用了ServletRequestAware接口,如下:public interface ServletRequestAware {
public void setServletRequest(HttpServletRequest request);
}当继承这个接口后,原本简单的Action看起来有点复杂了,但是这时可以获取HttpServerRequest对象来使用了。public class IoCForStruts2 implements ServletRequestAware {
private HttpServletRequest request;
public void setServletRequest(HttpServletRequest request) {
this.request = request;
}
public String execute() throws Exception {
// 可以开始使用request对象进行工作了
return Action.SUCCESS;
}
}