public class BaseAction extends ActionSupport {
protected final Log log = LogFactory.getLog(getClass());
private int pageNo = 1;
private int pageSize = 15;
//当前登陆用户
private Emp emp;
/**
*
* 获得Session
*/
public Map<String, Object> getSession() {
return ActionContext.getContext().getSession();
}
/**
*
* 获得ActionContext
*/
public ActionContext getActionContext() {
return ActionContext.getContext();
}
/**
* 获得HttpServletRequest
*/
public HttpServletRequest getHttpServletRequest() {
return ServletActionContext.getRequest();
}
/**
* 获得HttpServletResponse
*/
public HttpServletResponse getHttpServletResponse() {
return ServletActionContext.getResponse();
}
public HttpSession getHttpSession() {
return getHttpServletRequest().getSession();
}
/**
* 获得ServletContext
*/
public ServletContext getServletContext() {
return ServletActionContext.getServletContext();
}
/**
* 输出字符串
* @param message
* @throws Exception
*/
protected void write(String message)throws Exception{
getHttpServletResponse().setContentType("text/html");
getHttpServletResponse().setCharacterEncoding("utf-8");
getHttpServletResponse().getWriter().write(message);
getHttpServletResponse().getWriter().flush();
}
//============================= getter and setter =================================
public int getPageNo() {
return Math.max(1, pageNo);
}
public void setPageNo(int pageNo) {
this.pageNo = pageNo;
}
public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
public Emp getEmp() {
return emp;
}
public void setEmp(Emp emp) {
this.emp = emp;
}
}