今天看到Action类很有用,记录下来

 

public abstract class Action extends ActionSupport{

    private static final long serialVersionUID = 1L;

    protected final Log logger = LogFactory.getLog(this.getClass());

    protected Map<String,Object> jsonReader = new HashMap<String,Object>();

    //页号

    protected int page;

    //每页每行记录数

    protected int rows;

    ...排序等等

    //分页类

    protected Pager pager = new Pager();

    //向jsp返回的数据

    protected ResultVo resultVo = new ResultVo();

    //获取request便利方法

    protected HttpServletRequest getRequest(){

        return ServletActionContext.getRequest();

    }

    //获取response

    protected HttpServletResponse getResponse(){

        return ServletActionContext.getResponse();

    }

    / /获取session

    protected HttpSession getSession(){

        return getRequest().getSession();

    }

    / /获取session如果当前不存在且flag为true将自动创建一个

    protected HttpSession getSession(boolean flag){

        return getRequest().getSession(falg);

    }

    //获取ServletContext

    protected ServletContext getServletContext(){

        return ServletActionContext.getServletContext();

    }

}

你可能感兴趣的:(struts2,action)