Page Struts Hibernate Oracle Page Select Blog from 9CBS LifeTragedy
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, POS) 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, ',' Shawn ',' Marion ',' ',' A ',' F '); Insert Into Player (Player_ID, Team, DisplayName, Last_name, Middle_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) Values ('29968', 'Was', '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, Displa YNAME, LAST_NAME, MIDDLE_NAME, STATUS, POS) VALUES ('30029', 'Sea', 'Gary', 'Payton', ',' A ',' G '); Insert Into Player (Player_ID, Team, DisplayName, Last_name, middle_name, 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) Values ('30359,' ATL ',' Jason ',' Terry ',', 'A', 'g'); Insert Into Player Player_ID, Team, DisplayName, Last_name, Middle_Name, Status, POS, ',' 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"?> Column = "Player_ID" type = "string" length = "32"> public void setLabel_4 (String str) {this.label_4 = str;} public String getLabel_4 () {return this.label_4;} public String label_5 = ""; public void setLabel_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 void setLabel_8 (String str) {this.label_8 = str; } 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 getLab el_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 = S tr;} 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 .formean; import org.apache.struts.action.actionform; import javax.servlet.http.httpservletRequest; import org.apache.struts.Action.Apache.Struts.Action.Apache.Struts.Action.ActionForm; Import org.apache.struts.action.ActionMapping; import java.util. *; / ** * myeclipse struts * creection 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.hib.hibernate. *; import com.ecc.hibernate.hbm. *; import java.util. *; public class message exercion example {// - ----------------------------------------------- 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 * Itemsin PerPage-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 (); should (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.printstacktrace) } finally {Try {hbunit.closesession ();} catch (exception ex) {}}} private int getRecordsize ()} Private Int getRecordsize ()} private tx = null; session session = null; int totalcount = 0; try {session = hbunit. GetSession (); tx = session.begintransaction (); totalcount = ("Select Count (*) from player"). next ()) .intValue (); tx.commit (); returnot 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 peritems = 0; int today = 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"%>