> }
public String label_10 = ""; public void setLabel_10(String str) { this.label_10 = str; }
public String getLabel_10() { return this.label_10; }
public String label_11 = ""; public void setLabel_11(String str) { this.label_11 = str; }
public String getLabel_11() { return this.label_11; }
public String label_12 = ""; public void setLabel_12(String str) { this.label_12 = str; }
public String getLabel_12() { return this.label_12; }
public String label_13 = ""; public void setLabel_13(String str) { this.label_13 = str; }
public String getLabel_13() { return this.label_13; }
public String label_14 = ""; public void setLabel_14(String str) { this.label_14 = str; }
public String getLabel_14() { return this.label_14; }
public String label_15 = ""; public void setLabel_15(String str) { this.label_15 = str; }
public String getLabel_15() { return this.label_15; }
public String label_16 = ""; public void setLabel_16(String str) { this.label_16 = str; }
public String getLabel_16() { return this.label_16; }
public String label_17 = ""; public void setLabel_17(String str) { this.label_17 = str; }
public String getLabel_17() { return this.label_17; }
public String label_18 = ""; public void setLabel_18(String str) { this.label_18 = str; }
public String getLabel_18() { return this.label_18; }
public String label_19 = ""; public void setLabel_19(String str) { this.label_19 = str; }
public String getLabel_19() { return this.label_19; }
public String label_20 = ""; public void setLabel_20(String str) { this.label_20 = str; }
public String getLabel_20() { return this.label_20; }
public String label_21 = ""; public void setLabel_21(String str) { this.label_21 = str; }
public String getLabel_21() { return this.label_21; } } MessageForm.java:
//Created by MyEclipse Struts // XSL source (default): platform:/plugin/com.genuitec.eclipse.cross.easystruts.eclipse_3.8.2/xslt/JavaClass.xsl
package com.ecc.struts.message.formbean; import org.apache.struts.action.ActionForm; import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionErrors; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionMapping; import java.util.*; /** * MyEclipse Struts * Creation date: 01-06-2005 * * XDoclet definition: * @struts:form name="testRegistForm" */ public class MessageForm extends ActionForm { public MessageForm(){} private String label1="";
/** * @return */ public String getLabel1() { return label1; }
/** * @param string */ public void setLabel1(String string) { label1 = string; } private Vector meisai = new Vector(); public void setMeisai(Vector meisai) {this.meisai = meisai; } public Vector getMeisai(){return meisai; } private int currentPage=0; /** * @return */ public int getCurrentPage() { return currentPage; }
/** * @param i */ public void setCurrentPage(int i) { currentPage = i; } private int totalPage=0; /** * @return */ public int getTotalPage() { return totalPage; }
/** * @param i */ public void setTotalPage(int i) { totalPage = i; }
} MessageAction.java: //Created by MyEclipse Struts // XSL source (default): platform:/plugin/com.genuitec.eclipse.cross.easystruts.eclipse_3.8.2/xslt/JavaClass.xsl
package com.ecc.struts.message.action; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.struts.action.Action; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; import org.apache.struts.action.SessionActionMapping; import org.apache.struts.action.ActionError; import org.apache.struts.action.ActionErrors; import com.ecc.struts.message.formbean.*; import com.ecc.util.*; import java.security.*; import com.ecc.util.security.password.*; import com.ecc.exception.regist.*; import com.ecc.hibernate.db.*; import net.sf.hibernate.*; import net.sf.hibernate.cfg.*; import com.ecc.hibernate.*; import com.ecc.hibernate.hbm.*; import java.util.*; public class MessageAction extends Action{
// --------------------------------------------------------- Instance Variables
// --------------------------------------------------------- Methods
/** * Method execute * @param mapping * @param form * @param request * @param response * @return ActionForward */ private void setPage(ActionForm form,int currentPage){ Transaction tx=null; Session session=null; int totalCount=0; String playerid=""; String team=""; String displayname=""; int firstIndex=0; int itemsInPerPage=10; try{ MessageForm messageForm = (MessageForm) form; session = HbUnit.getSession(); tx= session.beginTransaction(); currentPage=messageForm.getCurrentPage(); if (currentPage<=0){ messageForm.setCurrentPage(1); firstIndex=0; }else { firstIndex=currentPage*itemsInPerPage-itemsInPerPage; } String sql="select player from Player as player"; Query query = session.createQuery (sql); query.setFirstResult(firstIndex); query.setMaxResults(itemsInPerPage); Iterator it=query.iterate(); Vector meisaiList=new Vector(); while(it.hasNext()){ Player player=(Player)it.next(); playerid=StrHandle.replaNull(player.getPlayerId()); team=StrHandle.replaNull(player.getTeam()); displayname=StrHandle.replaNull(player.getDisplayName()); MeisaiBean meisai=new MeisaiBean();
meisai.setLabel_1(playerid); meisai.setLabel_2(team); meisai.setLabel_3(displayname); meisaiList.add(meisai); } messageForm.setMeisai(meisaiList); tx.commit(); } catch(Exception ex){ try{ tx.rollback(); }catch(Exception eex){ } System.out.println(ex); ex.printStackTrace(); }finally{ try{ HbUnit.closeSession(); }catch(Exception ex){ } } } private int getRecordSize(){ Transaction tx=null; Session session=null; int totalCount=0; try{ session = HbUnit.getSession(); tx= session.beginTransaction(); totalCount=( (Integer) session.iterate("select count(*) from Player").next() ).intValue(); tx.commit(); return totalCount; } catch(Exception ex){ try{ tx.rollback(); }catch(Exception eex){ } System.out.println(ex); ex.printStackTrace(); return -1; }finally{ try{ HbUnit.closeSession(); }catch(Exception ex){ } } } public ActionForward execute( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { MessageForm messageForm = (MessageForm) form;
String target=""; int size=0; int perItemsPage=10; int modItems=0; int totalPages=0; int currentPage=0; try{ currentPage=messageForm.getCurrentPage(); size=getRecordSize(); if(size<=0){ target="noitemfound"; } else { totalPages=size/perItemsPage; modItems=size%perItemsPage; if(modItems>0)totalPages+=1; System.out.println("Record Size:"+size); System.out.println("Total page:"+totalPages); messageForm.setTotalPage(totalPages); setPage(form,currentPage); System.out.println("total page:"+totalPages); target="success"; } }catch(Exception ex){ System.out.println(ex); ex.printStackTrace(); } return (mapping.findForward(target)); } } Message.jsp如下: <%@ page language="java"%> <%@ page contentType="text/html; charset=GB2312" %> <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %> <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %> <%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %> <html> <head> <title>JSP for testRegistForm form</title> <STYLE type=text/css> FONT-SIZE: 9pt{ } A { COLOR: #000000; TEXT-DECORATION: none } A:hover { TEXT-DECORATION: underline } .bt { BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; FONT-SIZE: 9pt; BORDER-BOTTOM-WIDTH: 0px; WIDTH: 50px; CURSOR: hand; HEIGHT: 上一页 [1] [2] [3] 下一页 [系统软件]EXP-00008: ORACLE error 904 encountered的解决方… [常用软件]PB7 连接 Oracle 的配置方法 [Web开发]oracle Export and Import 简介 [Web开发]ADO访问Oracle结果集的心得 [JAVA开发]Struts+Spring+Hibernate组装web应用 [JAVA开发]JAVA:Hibernate 3新增XML关系持久性介绍 [JAVA开发]扩展 Hibernate 对各类数据源支持 [JAVA开发]Hibernate 3.0 的Formulas编程 [JAVA开发]Hibernate 3.0 的规则应用分析 [JAVA开发]Hibernate 3新增XML关系持久性介绍
|