import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;
import com.opensymphony.xwork2.ActionSupport;
public abstract class BaseAction extends ActionSupport implements ServletRequestAware, ServletResponseAware {
private static final long serialVersionUID = 1L;
public HttpServletRequest request;
public HttpServletResponse response;
public void setServletRequest(HttpServletRequest request) {
this.request = request;
}
public void setServletResponse(HttpServletResponse response) {
this.response = response;
}
/**
* 获得request
*
* @return
*/
public HttpServletRequest getRequest() {
return ServletActionContext.getRequest();
}
/**
* 获得response
*
* @return
*/
public HttpServletResponse getResponse() {
return ServletActionContext.getResponse();
}
/**
* 获得session
*
* @return
*/
public HttpSession getSession() {
return getRequest().getSession();
}
/**
* 获得servlet上下文
*
* @return
*/
public ServletContext getServletContext() {
return ServletActionContext.getServletContext();
}
public String getRealyPath(String path) {
return getServletContext().getRealPath(path);
}
}