描述一下Struts2如何将resquest ,response的对象封装到ServletActionContext对象里面的?
1个回答
展开全部
最简单暴力的,给你看下ServletActionContext源码,你就知道咋回事儿了......
/**
* Sets the HTTP servlet request object.
*
* @param request the HTTP servlet request object.
*/
public static void setRequest(HttpServletRequest request) {
ActionContext.getContext().put(HTTP_REQUEST, request);
}
/**
* Gets the HTTP servlet request object.
*
* @return the HTTP servlet request object.
*/
public static HttpServletRequest getRequest() {
return (HttpServletRequest) ActionContext.getContext().get(HTTP_REQUEST);
}
/**
* Sets the HTTP servlet response object.
*
* @param response the HTTP servlet response object.
*/
public static void setResponse(HttpServletResponse response) {
ActionContext.getContext().put(HTTP_RESPONSE, response);
}
/**
* Gets the HTTP servlet response object.
*
* @return the HTTP servlet response object.
*/
public static HttpServletResponse getResponse() {
return (HttpServletResponse) ActionContext.getContext().get(HTTP_RESPONSE);
}
思路的话,简单直接一点,通过注入来实现封装的~
/**
* Sets the HTTP servlet request object.
*
* @param request the HTTP servlet request object.
*/
public static void setRequest(HttpServletRequest request) {
ActionContext.getContext().put(HTTP_REQUEST, request);
}
/**
* Gets the HTTP servlet request object.
*
* @return the HTTP servlet request object.
*/
public static HttpServletRequest getRequest() {
return (HttpServletRequest) ActionContext.getContext().get(HTTP_REQUEST);
}
/**
* Sets the HTTP servlet response object.
*
* @param response the HTTP servlet response object.
*/
public static void setResponse(HttpServletResponse response) {
ActionContext.getContext().put(HTTP_RESPONSE, response);
}
/**
* Gets the HTTP servlet response object.
*
* @return the HTTP servlet response object.
*/
public static HttpServletResponse getResponse() {
return (HttpServletResponse) ActionContext.getContext().get(HTTP_RESPONSE);
}
思路的话,简单直接一点,通过注入来实现封装的~
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询