工厂类中生成command类的方法: 如果我不把command缓存到mapClass这个hashtalbe中就不会报上面的错,可我觉得缓存起来性能可能会好些。 public Command createCommand(String actionName) {
Command command;
try {
command = (Command)mapClass.get(actionName) ;
if(null == command)
{
Class obj = Class.forName(actionName);
command = (Command) obj.newInstance();
mapClass.put(actionName, command);
DebugLog .debug
}
}
catch (Exception ex) {
return null;
}
return command;
}
Command 方法:
public class NbdwCommand
extends Command {
DebugLog log = DebugLog.getInstance();
ErrorMessage message = ErrorMessage.getInstance();
boolean result = false;
Class prog = NbdwCommand.class;
public void execute() {
String actionId = (String) requester.getAttribute(GlobalCONST.ACTIONID);
m_url = (String) requester.getAttribute(GlobalCONST.PAGERES);
DB db = new DB();
try {
//list操作
if (actionId.equals(GlobalCONST.Glob_List)) {
//得到需要显示的页号
String strPageNo = request.getParameter("pageNo");
//默认返回值为1
pageNo = MathUtil.getPageNo(strPageNo);
NbdwWebImp webImp = new NbdwWebImp();
//得到当前页的记录
HashList list = new HashList(GlobalCONST.PAGE_SIZE);
String actionRes = request.getParameter("actionRes");
String sql = "";
String sqlTotal = "";
if (actionRes.equals("cj_nbdw_list")) {
sql = " select dw.* from njc_nbdw dw ,sys_yh yh where dw.zzmj=yh.yonghubianhao and dw.zzmj='" +
"160" + "'";
sqlTotal = "select count(*) as cnt from njc_nbdw dw where dw.zzmj='" +
"160" + "'";
}
else if (actionRes.equals("cx_nbdw_list")) {
sql = getSql();
sqlTotal = "select count(*) as cnt from njc_nbdw dw,sys_zz zz where " +
getWhere();
}
list = webImp.selectNbdw(db, sql, sqlTotal, GlobalCONST.PAGE_SIZE,pageNo);
int max = list.maxNum;
//得到共有多少页
totalPage = ( (Integer) (list.getRow(list.maxNum - 1).get("totalPage"))).
intValue();
if(totalPage ==0)
list = new HashList(0);
request.setAttribute("pageNo", "" + pageNo);
request.setAttribute("totalPage", "" + totalPage);
//修改
//request.setAttribute("pageAction",actionId);
request.setAttribute("pageAction", actionRes);
request.setAttribute("list", list);
}
....
finally
{
db.close();
forward(m_url);
}
}