ITeye博客

tag

kkcheng · 2011-06-01 21:35 · 编程语言 · Markdown

http://kickjava.com/src/org.apache.taglibs.i18n.index.htm

vml:http://www.mzwu.com/pic/20070509/sx.htm

Struts2的Action在实现com.opensymphony.xwork2.Preparable接口后,就可以重写prepare()方法 此时在Action中,prepare()方法的执行点是在:setXxx()和execute()的执行之前

import java.util.HashMap; import java.util.Map;

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

import org.apache.log4j.Logger;

import com.opensymphony.webwork.ServletActionContext; import com.opensymphony.webwork.dispatcher.DefaultActionSupport; import com.opensymphony.xwork.Preparable;

public class BaseAction extends DefaultActionSupport implements Preparable { private static final Logger log = Logger.getLogger(BaseAction.class);

protected HttpServletRequest request;
protected HttpServletResponse response;
protected HttpSession session;

protected Map mapIn = new HashMap();
protected Map mapOut = new HashMap();
protected ListWrapper listOut = new ListWrapper();

//分页信息
private int currPage;
private int pageSize;
protected String uri;

//计算出的分页信息
private int begin;
private int end;

protected String echoInfo = null;

public void prepare() throws Exception
{
	log.debug("现在开始初始化:");
	request = ServletActionContext.getRequest();
	response = ServletActionContext.getResponse();
	session = request.getSession();
	session.setAttribute("echo_info",echoInfo);
}



public ListWrapper getListOut()
{
	return listOut;
}



public void setListOut(ListWrapper listOut)
{
	this.listOut = listOut;
}



public Map getMapIn()
{
	return mapIn;
}

public void setMapIn(Map mapIn)
{
	this.mapIn = mapIn;
}

public Map getMapOut()
{
	return mapOut;
}

public void setMapOut(Map mapOut)
{
	this.mapOut = mapOut;
}



public String getEchoInfo()
{
	return echoInfo;
}

public void setPageInfo(PageInfo pageInfo)
{
	request.setAttribute("pageInfo",pageInfo);
}

protected String generateURI()
{
	return "" ;
}

public int getRecordBegin()
{
	begin = (getCurrPage() - 1) * getPageSize() + 1;
	
	return begin;
}

public int getRecordEnd()
{
	end = getRecordBegin() + getPageSize() - 1;
	
	return end;
}

public int getCurrPage()
{
	currPage = RequestParamUtil.getInt(request,"currPage",1);
	return currPage;
}

public int getPageSize()
{
	pageSize = RequestParamUtil.getInt(request,"pageSize",10);
	return pageSize;
}

}

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。