Struts2中调用request方法
Struts2跟servlet不一样.不能直接调用request
但是有很多地方又需要用到request
通过request可以操作很多东西.
比如:
HttpSession session = request.getSession();session.setAttribute("object", object);request.setAttribute("object", object);等等...
import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import org.apache.struts2.interceptor.ServletRequestAware;import org.apache.struts2.interceptor.ServletResponseAware;import com.opensymphony.xwork2.ActionSupport;public class BaseAction extends ActionSupport implements ServletRequestAware, ServletResponseAware{private static final long serialVersionUID = 1L;public HttpServletRequest request;public HttpServletResponse response;@Overridepublic void setServletResponse(HttpServletResponse response) {this.response=response;}@Overridepublic void setServletRequest(HttpServletRequest request) {this.request=request;}}