Struts2 与普通的java内通信 也就是所谓的 Action类 来获取servlet中request对象和response对象

 

方法1:

implements ServletRequestAware, ServletResponseAware

public class Hello implements ServletRequestAware, ServletResponseAware {

    private HttpServletRequest request;
    private HttpServletResponse response;


    @Override
    public void setServletRequest(HttpServletRequest httpServletRequest) {
        this.request = httpServletRequest;
    }

    @Override
    public void setServletResponse(HttpServletResponse httpServletResponse) {
        this.response = httpServletResponse;
    }
}

 

方法2

在普通java类中通过ServletActioContext对象来获取

Struts2 与普通的java内通信 也就是所谓的 Action类 来获取servlet中request对象和response对象

 

上一篇:Struts简介


下一篇:springmvc拦截器