Struts2接收请求参数原理

当用户提交请求的时候,JSP会把它封闭成内置的Request对象(此对象是接口HttpServletRequest的一个实现,该接口是java扩展包,javax中的).


在 struts2的FilterDispatcher时候,  FilterDispatcher便把request封装到了ActionContext,由struts2的ServletActionContext对象进行管理。


如源码所示,在ServletActionContext中,
public static void setRequest(HttpServletRequest request) {
        ActionContext.getContext().put(HTTP_REQUEST, request);
    }


public static HttpServletRequest getRequest() {
        return (HttpServletRequest) ActionContext.getContext().get(HTTP_REQUEST);
    }


所以在action.java中,就可以用
HttpServletResponse response = ServletActionContext.getResponse();

HttpServletRequest request = ServletActionContext.getRequest();


来完成对HttpServletResonse和HttpServletRequest的处理。

posted on 2012-05-08 16:42  java课程设计例子  阅读(152)  评论(0编辑  收藏  举报