Mainly by: message.jspMessageFormMessageActionPlayer.hbm.xmlstruts-config.xmlMeisaiBean.java achieved: look at the database structure: CREATE TABLE player (PLAYER_ID VARCHAR (32) PRIMARY KEY, TEAM VARCHAR (3), displayName VARCHAR (100), LAST_NAME VARCHAR (100), middle_name varchar (100), Status Varchar (32), POS varchar (1), PPG Integer Default 25);
INSERT INTO Player (Player_ID, Team, DisplayName, Last_name, Middle_name, Status, POS) Values ('2113999', 'DAL', 'Dirk', NULL, ', NULL,' F '); Insert Into Player (Player_ID, Team, DisplayName, Last_name, Middle_name, Status, POS, Values ('30361', 'IND', 'RON', 'ARTEST', '', 'A', 'g'); Insert Into Player (Player_ID, Team, DisplayName, Last_name, Middle_Name, Status, POS) VALUES ('30273', 'orl', 'TRACY', 'MCGRADY', '', 'A', 'F'); INSERT INTO Player (Player_ID, Team, DisplayName, Last_name, middle_name, status, pos) Values ('30190', 'LAL', 'Kobe', 'Bryant', ',' A ',' g '); Insert Into Player (Player_ID, Team, DisplayName, Last_name, Middle_name, status, pos) Values ('30328', 'sea', 'rashard', 'Lewis', '', 'A', 'g'); Insert Into Player (Player_ID, Team, DisplayName, Last_name, Middle_name, Status, POS) VALUES ('30197', 'NJN', 'Kerry', 'Kittles', '', 'A', 'G'); Insert Into Player (Player_ID, Team, DisplayName, Last_name, Middle_Name, Status, POS) VALUES ('30341', 'Hou', 'Steve', 'Francis', '', 'A', 'G'); Insert Into Player (Player_ID, Team, DisplayName, Last_name, Middle_Name, Status, P OS) VALUES ('30146', 'Min', 'Kevin', 'Garnett', '', 'A', 'F'); Insert Into Player (Player_ID, Team, DisplayName, Last_name, Middle_Name, Status, POS) VALUES ('2113993', 'BOS', 'Paul', 'Pierce', '', 'A', 'g');
Insert Into Player (Player_ID, Team, DisplayName, Last_name, Middle_Name, Status, POS) Values ('30050', 'NJN', 'Jason ",' KIDD ',' ',' A ',' G '); Insert Into Player (Player_ID, Team, DisplayName, Last_name, Middle_Name, Status, POS) VALUES ('30215', 'ATL', 'Shareef', 'Abdur-Rahim', '', 'I', 'F'); Insert Into Player (Player_ID, Team, DisplayName, Last_Name, Middle_Name, Status, POS) Values ('1861922', 'orl', 'Mike', 'Miller', '', 'I', 'F'); Insert Into Player Player_ID, Team, DisplayName, Last_name, Middle_name, Status, POS) Values ('30144', 'ATL', 'Glenn', 'Robinson', ',' A ',' F '); Insert Into Player (Player_ID, Team, DisplayName, Last_name, Middle_Name, Status, POS, Values ('2019703', 'GSW', 'Gilbert', 'Arenas', '', 'A', 'G'); Insert Into Player (Player_ID, Team, DisplayName, Last_name, Middle_Name, Status, POS, VALUES ('2028505', 'uth', 'andrei', 'Kirilenko', '', 'I', 'F'); Insert Into Player (Player_ID, Team, DisplayName, Last_name, middle_name, status, pos) Values ('30382', 'pho', 'Shawn', 'Marion', '', 'A', 'F'); Insert Into Player (Player_ID, Team, DisplayName, Last_name, M IDDLE_NAME, STATUS, POS VALUES ('29941', 'Sea', 'Brent', 'Barry', '', 'A', 'G'); Insert Into Player (Player_ID, Team, DisplayName, Last_name, Middle_name, Status, POS) VALUES ('2114000', 'DAL', 'Michael', 'Finley', '', 'A', 'G');
INSERT INTO Player (Player_ID, Team, DisplayName, Last_name, Middle_Name, Status, POS) Values ('30187', 'Bos',' Antoine ',' Walker ',', 'A', 'F'); Insert Into Player (Player_ID, Team, DisplayName, Last_name, Middle_Name, Status, POS) Values ('30234', 'Sac', 'Bobby', 'Jackson', ',' A ',' G '); Insert Into Player Player_ID, Team, DisplayName, Last_name, Middle_name, Status, POS, ',' Jerry ',' Stackhouse ',' ',' A ',' G '); Insert Into Player (Player_ID, Team, DisplayName, Last_name, Middle_name, Status, POS, Values ('29944', 'Sac', 'Doug', 'Christie', '', 'I', 'G'); Insert Into Player (Player_ID, Team, DisplayName, Last_name, Middle_Name, Status, POS) Values ('30095', 'Chi', 'Donyll', 'Marshall', '', 'A', 'F'); Insert Into Player (Player_ID, Team, DisplayName, Last_name, middle_name, status, pos) Values ('2028865', 'ATL', 'Ira', 'Newble', '', 'A', 'F'); INSERT INTO Player (Player_ID, Team, DisplayName, Last_name, Middle_name, status, pos) VALUES ('30029,' Sea ',' Gary ',' Payton ',', 'A', 'g'); Insert Into Player (Player_ID, Team, DisplayName, Last_name, Middle_n AME, STATUS, POS) VALUES ('30141', 'Tor', 'Voshon', 'LENARD', '', 'A', 'G'); INSERT INTO Player (Player_ID, Team, DisplayName, Last_name, Middle_Name, Status, POS) VALUES ('30020', 'Mil', 'Toni', 'Kukoc', '', 'A', 'F');
INSERT INTO Player (Player_ID, Team, DisplayName, Last_name, Middle_Name, Status, POS) Values ('30154', 'Nor', 'Pj', 'Brown', '', 'A', 'F'); Insert Into Player (Player_ID, Team, DisplayName, Last_name, Middle_name, Status, POS) Values ('30125', 'MIA', 'EDDIE', 'Jones', '', 'A', 'G'); Insert Into Player Player_ID, Team, DisplayName, Last_name, Middle_Name, Status, POS, 'Jason,' Terry ',' ',' A ',' g '); Insert Into Player (Player_ID, Team, DisplayName, Last_name, Middle_Name, Status, POS, Values ('30291', 'uth', 'Matt', 'Harpring', ',' A ',' F '); Insert Into Player (Player_ID, Team, DisplayName, Last_name, Middle_Name, Status, POS) Values ('30228', 'Mil', 'Ray', 'Allen', '', 'A', 'g'); Insert Into Player (Player_ID, Team, DisplayName, Last_name, middle_name, status, pos) Values ('2028503', 'SEA', 'VLADIMIR', 'RADMANOVIC', '', 'A', 'F'); the corresponding Player.hbm.xml is as follows: XML Version = "1.0" encoding = "uTF-8"?>
Public Class Meisaibean Implements Serializable {
Public Meisaibean () {}
Public string label_1 = "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "
Public string getLabel_1 () {return this.label_1;}
Public String Label_2 = "" "; PUBLIC VOID SETLABEL_2 (String Str) {this.label_2 = Str;}
Public string getlabel_2 () {return this.label_2;}
Public String Label_3 = "" "" "" "PUBLIC VOID SETLABEL_3 (String Str) {this.label_3 = Str;} public string getLabel_3 () {return this.label_3;}
Public String Label_4 = "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "
Public String getLabel_4 () {Return this.Label_4;}
Public string label_5 = "" "" "; String Str) {this.label_5 = Str;}
Public String getLabel_5 () {return this.label_5;}
Public String Label_6 = "" "; PUBLIC VOID SetLabel_6 (String Str) {this.label_6 = Str;}
Public String getLabel_6 () {return this.label_6;}
Public String Label_7 = ""; PUBLIC VOID SetLabel_7 (String Str) {this.label_7 = Str;}
Public string getLabel_7 () {return this.label_7;}
Public string label_8 = "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "
Public string getlabel_8 () {return this.Label_8;}
Public string label_9 = "" ", public void setlabel_9 (string str) {this.label_9 = Str;}
Public string getlabel_9 () {return this.label_9;}
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 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 an 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.actionerroters; import com.ecc.struts.MPort com.ecc.util. *; Import java.security. *; Import com.ecc.util.security .pausword. *; 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 message --------------------------------------- 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.getd) ISPLAYNAME ()); 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 {{hbunit.closesis ();} catch (exception ex) {}} } private int getRecordsize () {Transaction tx = null; session session = null; int totalcount = 0; try {session = hbUnit.getations (); tx = session.begintransaction (); totalcount = ((integer) session.Itemate "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 / peritems = size% peritemspage; if (MODITEMS> 0) Totalpages = 1; System.out.Println ("Record Size:" size) System.out.println ("Total Page: Totalpages); MessageForm.SettotalPage (Totalpages); SESTEM.OT.Println (" Total Page: Totalpages); target = "success" ;}}}} catch (exception ex) {system.out.println (ex.printstacktrace ();} return (maping.findforward (target));}} message.jsp as follows: <% @ 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"%>