请教大家pager-taglib标签在struts中的用法

07-07-11 zhouzhi185
数据库查询的片断如下:
public Collection getFaultwithtype(String argType)
throws Exception {
PreparedStatement prepStmt = null;
ResultSet rs = null;
ArrayList<FaultBean> list = new ArrayList<FaultBean>();
String sql = "select fnum, fdate, fweek, substring(starttime,1,2)+':'+substring(starttime,3,2) as starttime, substring(endtime,1,2)+':'+substring(endtime,3,2) as endtime, ftype, fplace, ffinish, fperson, flinkman, fphone, funit, fbehave, fcause, fnote from kpfault where ftype = ?";
Connection con = null;
try {
con = getConnection();
if (con.isClosed()) {
throw new IllegalStateException("ERROR.THE CONNECTION ISCLOSED");
}
prepStmt = con.prepareStatement(sql);
prepStmt.setString(1, argType);
rs = prepStmt.executeQuery();
while (rs.next()) {
FaultBean fB = new FaultBean();
int fnum = rs.getInt("fnum");
String fnum1 = Integer.toString(fnum);
fB.setFnum(fnum1);
fB.setFdate(rs.getString("fdate"));
String fweek = rs.getString("fweek");
if (fweek != null || fweek.equals("")) {
fweek = new String(fweek.getBytes("ISO-8859-1"), "GB2312");
}
fB.setFweek(fweek);
fB.setStarttime(rs.getString("starttime"));
fB.setEndtime(rs.getString("endtime"));
String ftype = rs.getString("ftype");
if (ftype != null || ftype.equals("")) {
ftype = new String(ftype.getBytes("ISO-8859-1"), "GB2312");
}
fB.setFtype(ftype);
String fplace = rs.getString("fplace");
if (fplace != null || fplace.equals("")) {
fplace = new String(fplace.getBytes("ISO-8859-1"), "GB2312");
}
fB.setFplace(fplace);
String ffinish = rs.getString("ffinish");
if (ffinish != null || ffinish.equals("")) {
ffinish = new String(ffinish.getBytes("ISO-8859-1"),
"GB2312");
}
fB.setFfinish(ffinish);
String fperson = rs.getString("fperson");
if (fperson != null || fperson.equals("")) {
fperson = new String(fperson.getBytes("ISO-8859-1"),
"GB2312");
}
fB.setFperson(fperson);
String flinkman = rs.getString("flinkman");
if (flinkman != null || flinkman.equals("")) {
flinkman = new String(flinkman.getBytes("ISO-8859-1"),
"GB2312");
}
fB.setFlinkman(flinkman);
fB.setFphone(rs.getString("fphone"));
String funit = rs.getString("funit");
if (funit != null || funit.equals("")) {
funit = new String(funit.getBytes("ISO-8859-1"), "GB2312");
}
fB.setFunit(funit);
String fbehave = rs.getString("fbehave");
if (fbehave != null || fbehave.equals("")) {
fbehave = new String(fbehave.getBytes("ISO-8859-1"),
"GB2312");
}
fB.setFbehave(fbehave);
String fcause = rs.getString("fcause");
if (fcause != null || fcause.equals("")) {
fcause = new String(fcause.getBytes("ISO-8859-1"), "GB2312");
}
fB.setFcause(fcause);
String fnote = rs.getString("fnote");
if (fnote != null || fnote.equals("")) {
fnote = new String(fnote.getBytes("ISO-8859-1"), "GB2312");
}
fB.setFnote(fnote);
list.add(fB);
}
} catch (SQLException ex) {
ex.printStackTrace();
} finally {
closeResultSet(rs);
closePrepStmt(prepStmt);
closeConnection(con);
}
return list;

}

zhouzhi185
2007-07-11 11:15
查询的action如下:
public class QueryFaultAction extends Action {
/*
* Generated Methods
*/

/**
* Method execute
*
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
* @throws Exception
*/
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
FaultActionForm faultActionForm = (FaultActionForm) form;
String r_type = (faultActionForm.getR_type()).trim();
String argType = (faultActionForm.getFtype()).trim();
argType = new String(argType.getBytes("GB2312"), "ISO-8859-1");
String argDate = (faultActionForm.getFdate()).trim();
try {
FaultCtrl sqlctrl = new FaultCtrl();
ArrayList arrayList = new ArrayList();
if (r_type.equals("withtype")) {
arrayList = (ArrayList) sqlctrl.getFaultwithtype(argType);
}
if (r_type.equals("withdate")) {
arrayList = (ArrayList) sqlctrl.getFaultwithdate(argDate);
}
request.setAttribute("allfB", arrayList);
return mapping.findForward("success");
} catch (Exception ex) {
ex.printStackTrace();
return null;
}
}
}

banq
2007-07-16 13:32
只贴代码,不写文档和目的。神仙才能回答你问题。

而且还在使用极其原始的中文编码转换,一个个使用getBytes("ISO-8859-1"), "GB2312方式,如果有1000隔字段,你写1000次吗?

参考本站的中文终极解决方案

猜你喜欢