Struts2中BaseAction的设计,欢迎指正

package com.sinovatech.cms.common.web.action;

import java.io.InputStreamReader;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;
import org.apache.struts2.interceptor.SessionAware;

import com.opensymphony.xwork2.ActionSupport;
import com.sinovatech.cms.common.constant.SysConstants;
import com.sinovatech.cms.common.model.entity.PageBean;
import com.sinovatech.cms.common.model.entity.PageRequest;
/**
 * action的Base基类
 * 
 * @author [email protected]
 * @since 2013-03-13
 */
public class BaseAction extends ActionSupport implements SessionAware,ServletRequestAware, ServletResponseAware{
	/**serialVersionUID**/
	private static final long serialVersionUID = 4446523818897848988L;
	/**通用日志对象**/
	protected Logger logger = Logger.getLogger(this.getClass());
	/**request对象*/
	protected HttpServletRequest request;
	/**response对象*/
	protected HttpServletResponse response; 
	/**分页对象*/
	protected PageBean page;
	/**当前页对象*/
	protected Integer currentPage = SysConstants.PAGE_CURRENT_PAGE;
	/**当前页数量对象*/
	protected Integer pageSize = SysConstants.PAGE_PAGE_SIZE;
	/**信息代码*/
	protected Long msgCode;
	/**返回页面的信息*/
	protected String messageInfo;
	/**ajax是否成功的标志 0-成功 1-失败 2-权限不足*/
	protected int isSuccess = SysConstants.DEFAULT_SUCCESS_STATUS;
	/**返回的页面名称*/
	protected String resultJsp;
	/**列表页的地址**/
	protected String listUrl;
	/**模块名称*/
	protected String moduleName;
	/**页面返回的id的数组*/
	protected String[] ids;
	/**分页查询参数的载体**/
	protected PageRequest pageRequest;
	/**
	 * 以流的形式获取请求参数
	 * @param request
	 * @return
	 */
	protected String getParameterString(HttpServletRequest request){
		String x = "";
		try {
			InputStreamReader reader = new InputStreamReader(request.getInputStream(), "UTF-8"); 
			char[] buff = new char[1024]; 
			int length = 0; 
			while ((length = reader.read(buff)) != -1){
				x = new String(buff, 0, length); 
			}
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("获取请求参数报错!");
		}
		 return x;
	}
	public void setSession(Map<String, Object> arg0) {}
	public void setServletRequest(HttpServletRequest request) {
		this.request=request;	
	}
	public void setServletResponse(HttpServletResponse response) {
		this.response=response;	
	}
	public Integer getCurrentPage() {
		return currentPage;
	}
	public void setCurrentPage(Integer currentPage) {
		this.currentPage = currentPage;
	}
	public Integer getPageSize() {
		return pageSize;
	}
	public void setPageSize(Integer pageSize) {
		this.pageSize = pageSize;
	}
	public PageBean getPage() {
		return page;
	}
	public void setPage(PageBean page) {
		this.page = page;
	}
	public String getMessageInfo() {
		return messageInfo;
	}
	public void setMessageInfo(String messageInfo) {
		this.messageInfo = messageInfo;
	}
	public int getIsSuccess() {
		return isSuccess;
	}
	public void setIsSuccess(int isSuccess) {
		this.isSuccess = isSuccess;
	}
	public String getResultJsp() {
		return resultJsp;
	}
	public void setResultJsp(String resultJsp) {
		this.resultJsp = resultJsp;
	}
	public Long getMsgCode() {
		return msgCode;
	}
	public void setMsgCode(Long msgCode) {
		this.msgCode = msgCode;
	}
	public String[] getIds() {
		return ids;
	}
	public void setIds(String[] ids) {
		this.ids = ids;
	}
	public String getModuleName() {
		return moduleName;
	}
	public void setModuleName(String moduleName) {
		this.moduleName = moduleName;
	}
	public PageRequest getPageRequest() {
		return new PageRequest(currentPage,pageSize);
	}
	public void setPageRequest(PageRequest pageRequest) {
		this.pageRequest = pageRequest;
	}
	public Logger getLogger() {
		return logger;
	}
	public void setLogger(Logger logger) {
		this.logger = logger;
	}
	public String getListUrl() {
		return listUrl;
	}
	public void setListUrl(String listUrl) {
		this.listUrl = listUrl;
	}
	
}

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