STRUTS HIBERNATE ORACLE tab 9cbs lifetragedy mainly selected from: 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 (STATUS, POS) '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, Middl E_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, 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, '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, Middle Le_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_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, ',' 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) 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) VA Lues ('2028503', 'SEA', 'VLADIMIR', 'RADMANOVIC', '', 'A', 'F'); the corresponding Player.hbm.xml is as follows: XML Version = "1.0" Encoding = " UTF-8 "?>
Http://hibernate.sourceForge.Net/Hibernate-mapping-2.0.dtd"> "Hibernate-mapping" !-- Test Player ->
} 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 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 THISLIC STRING LABEL_9 = ""; PUBLIC VOID SETLABEL_9 (String Str) {this.label_9 = Str;} PUBL ic 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 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;} Publ ic 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.XSLPACKAGE.ACC.STRUTS.MPORT 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 c 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.xslpackage 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.ActionerRuts.Mport com.ecc.struts.MPort com.ecc.util. *; import java.security. *; import com.ecc.util.security.password Import com.ecist. *; import com.ecc.hibernate.db. *; import net.sf.hibernate. *; import net.sf.hibernate.cfg. *; import com.ecc. 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.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.getations (); tx = session.begintransaction (); totalcount = ((Integer) "Session.Ikeer"). 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.closesis ();} catch (exception ex) {}}}} public actionforward execute form (ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {MessageForm messageForm = (MessageForm); String target = ""; int size = 0; int perItemsPage = 10; i nt 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); SESTEM.OUT.PRINTLN ("Total Page: Totalpages); target =" success ";}} catch (exception ex) {system.out.println (EX ); 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"%>