tag

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;
}



}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值