锘??xml version="1.0" encoding="utf-8" standalone="yes"?>
line[j]鏄澶嶅埗鐨勪竴琛?Action涓彲浠ヨ幏鍙栧埌瑕佸鍒剁殑琛岀殑ID.
鍥犱負line[j]涓湁寰堝灞炴?瑕佹槸涓涓竴涓殑灞炴у幓get,鐒跺悗set鐨勮瘽,浠g爜閲忎細
寰堝ぇ,鑰屼笖浼氬嚭鐜板緢澶氬啑浣欎唬鐮併?br>榪欐槸鎴戣澶嶅埗鍑烘潵鐨勪竴琛?br>if (j == rowId && !line[j].getNewRecord()) {
rowList.add(line[j]);
//灝嗚繖涓琛屽叏閮ㄥ鍒?br> }
鐜板湪瑕佷嬌寰楀叾涓殑鏌愬嚑涓睘鎬у鍒跺嚭鏉ヤ負絀?br>鍒欓渶瑕佷竴涓竴涓殑set,get.
if (j == rowId && !line[j].getNewRecord()) {
CreateDeliveryLineRow cdlr = new CreateDeliveryLineRow ();
if(line[j].getMfgLot() != null){
cdlr.setMfgLot = null;
}
銆傘傘傘傘傘?br> rowList.add(cdlr);
//灝嗚繖涓琛屽叏閮ㄥ鍒?br> }
浠ヤ笅鏄瘮杈冨ソ鐨勮В鍐蟲柟妗?
鍒╃敤apache鐨刢ommon綾諱腑鐨凚eanUtils鏉ュ疄鐜板璞″睘鎬х殑澶嶅埗
if (j == rowId && !line[j].getNewRecord()) {
CreateDeliveryLineRow row = new CreateDeliveryLineRow();
BeanUtils.copyProperties(row,line[j]);銆銆銆//澶嶅埗鍑哄璞ine[j],灝嗗叾灞炴ц祴浜坮ow
row.setQuantity(null); //鍦╮ow涓交鏉劇殑瀹炵幇瀵規(guī)煇鍑犱釜灞炴х殑鎺у埗
row.setMfgLot(null);
row.setMiniQuantity(null);
row.setBoxQuantity(null);
rowList.add(row);
//rowList.add(cdr);
}
===================================================
CreateDeliveryForm getForm = (CreateDeliveryForm) form;
銆傘傘傘傘傘?br>CreateDeliveryLineRow[] line = getForm.getLine();
if (line != null && line instanceof CreateDeliveryLineRow[]) {
int size = line.length;
for (int j = 0; j < size; j++) {
if (!line[j].getNewRecord() && !line[j+1].getNewRecord()) {
if (line[j].getBoxQuantity() == 0L) {
line[j].setBoxQuantity(null);
}
if (line[j].getMiniQuantity() == 0L) {
line[j].setMiniQuantity(null);
}
if (line[j].getQuantity() == 0D) {
line[j].setQuantity(null);
}
rowList.add(line[j]);
}
if (j == rowId && !line[j].getNewRecord()) {
CreateDeliveryLineRow row = new CreateDeliveryLineRow();
BeanUtils.copyProperties(row,line[j]);
row.setQuantity(null);
row.setMfgLot(null);
row.setMiniQuantity(null);
row.setBoxQuantity(null);
rowList.add(row);
//rowList.add(cdr);
}
}
}
聽<welcome-file-list>
聽聽聽 <welcome-file>search.jsp</welcome-file>
聽</welcome-file-list>
2.dwr.xml
聽<dwr>
聽聽聽 <allow><convert convert="bean"聽 match="dwr.sample.Apartment"/>
聽聽聽 <create>
聽聽聽聽聽聽聽聽聽聽 <creator="new" javascript="ApartmentDAO" class="dwr.sample.ApartmentDAO">
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 <include method="findApartments"/>
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 <include method="countApartments"/>
聽聽聽聽聽聽聽聽聽聽 </creator>
聽聽聽 </create>
聽聽聽 </allow>
</dwr>
3.DB
CREATE TABLE APARTMENTS (id INTEGER, bedrooms INTEGER, bathrooms INTEGER, price INTEGER, address VARCHAR, city VARCHAR, province VARCHAR);
INSERT INTO APARTMENTS VALUES (16001, 1, 1, 850, '123 King St. East', 'Toronto', 'ON');
INSERT INTO APARTMENTS VALUES (16002, 2, 1, 1000, '1023 Yonge Ave.', 'Toronto', 'ON');
INSERT INTO APARTMENTS VALUES (16003, 2, 2, 1050, '27 Winchester St.', 'Toronto', 'ON');
4.Apertment.java
鏅氱殑javabean
5.DBUtils.java
聽聽聽鏁版嵁搴撻摼鎺ョ被
聽聽 public class DBUtils {
聽/*
聽 * Creates the sample data (table and records).
聽 */
聽public static void setupDatabase(BufferedReader reader) {
聽聽Connection c = null;
聽聽Statement stmt = null;
聽聽try {
聽聽聽c = openConnection();
聽聽聽stmt = c.createStatement();
聽聽聽// reads the file with the SQL statements
聽聽聽String line;
聽聽聽while ((line = reader.readLine()) != null) {
聽聽聽聽stmt.execute(line);
聽聽聽}
聽聽聽stmt.close();
聽聽聽c.close();
聽聽} catch (IOException e) {
聽聽聽e.printStackTrace();
聽聽} catch (SQLException e) {
聽聽聽e.printStackTrace();
聽聽} finally {
聽聽聽try {
聽聽聽聽stmt.close();
聽聽聽聽c.close();
聽聽聽} catch (SQLException e) {
聽聽聽聽e.printStackTrace();
聽聽聽}
聽聽}
聽}
聽
聽/*
聽 * Opens a database connection.
聽 */
聽public static Connection openConnection() throws SQLException {
聽聽Connection c = DriverManager.getConnection("jdbc:hsqldb:mem:dwr-sample", "sa", "");
聽聽return c;
聽}
聽
}
6.ContextListener.java
聽聽 瀹炵幇浜哠ervletContextListerer鎺ュ彛鐨勭被
聽聽 public class ContextListener implements javax.servlet.ServletContextListener {
聽/**
聽 * This method is invoked when the Web Application has been removed and is
聽 * no longer able to accept requests.
聽 * @param event
聽 */
聽public void contextDestroyed(ServletContextEvent event) {
聽}
聽/**
聽 * This method is invoked when the Web Application is ready to service requests.
聽 * @param event
聽 */
聽public void contextInitialized(ServletContextEvent event) {
聽聽try {
聽聽聽// load the driver
聽聽聽Class.forName("org.hsqldb.jdbcDriver");
聽聽聽// create the table and add sample data
聽聽聽InputStreamReader in = new InputStreamReader(getClass().getClassLoader().getResourceAsStream("db.sql"));
聽聽聽BufferedReader reader = new BufferedReader(in);
聽聽聽DBUtils.setupDatabase(reader);
聽聽} catch (ClassNotFoundException e) {
聽聽聽e.printStackTrace();
聽聽}
聽聽
聽}
}
7.ApartmentDAO.java
聽聽 涓氬姟閫昏緫灞?br />聽聽 public class ApartmentDAO {
聽
聽/**
聽 * Returns the available apartments based on the search criteria.
聽 * @param bedrooms minimum number of bedrooms
聽 * @param bathrooms minimum number of bathrooms
聽 * @param price maximum price to be paid
聽 * @return
聽 */
聽public Collection findApartments(int bedrooms, int bathrooms, int price) {
聽聽Collection list = new Vector();
聽聽String sql = "select * from APARTMENTS" +
聽聽聽聽createSearchWhereClause(bedrooms, bathrooms, price) +
聽聽聽聽"order by bedrooms, bathrooms, price";
聽聽// define db variables
聽聽Connection c = null;
聽聽Statement stmt = null;
聽聽try {
聽聽聽c = DBUtils.openConnection();
聽聽聽stmt = c.createStatement();
聽聽聽// just run the sql statement
聽聽聽ResultSet rs = stmt.executeQuery(sql);
聽聽聽while(rs.next()) {
聽聽聽聽Apartment apartment = this.getApartment(rs);
聽聽聽聽list.add(apartment);
聽聽聽}
聽聽} catch (SQLException e) {
聽聽聽e.printStackTrace();
聽聽} finally {
聽聽聽try {
聽聽聽聽stmt.close();
聽聽聽聽c.close();
聽聽聽} catch (SQLException e) {
聽聽聽聽e.printStackTrace();
聽聽聽}
聽聽}
聽聽return list;
聽}
聽
聽/**
聽 * Returns the number of available apartments based on the search criteria.
聽 * @param bedrooms minimum number of bedrooms
聽 * @param bathrooms minimum number of bathrooms
聽 * @param price maximum price to be paid
聽 * @return
聽 */
聽public int countApartments(int bedrooms, int bathrooms, int price) {
聽聽String sql = "select count(*) as total from APARTMENTS" + createSearchWhereClause(bedrooms, bathrooms, price);
聽聽int numberApartments = -1;
聽聽// define db variables
聽聽Connection c = null;
聽聽Statement stmt = null;
聽聽try {
聽聽聽c = DBUtils.openConnection();
聽聽聽stmt = c.createStatement();
聽聽聽// just run the sql statement
聽聽聽ResultSet rs = stmt.executeQuery(sql);
聽聽聽if (rs.next()) {
聽聽聽聽numberApartments = rs.getInt("total");
聽聽聽}
聽聽} catch (SQLException e) {
聽聽聽e.printStackTrace();
聽聽} finally {
聽聽聽try {
聽聽聽聽stmt.close();
聽聽聽聽c.close();
聽聽聽} catch (SQLException e) {
聽聽聽聽e.printStackTrace();
聽聽聽}
聽聽}
聽聽
聽聽return numberApartments;
聽}
聽
聽/**
聽 * Creates a Unit object from the database.
聽 * @param rs
聽 * @return
聽 * @throws SQLException
聽 */
聽private Apartment getApartment(ResultSet rs) throws SQLException {
聽聽Apartment ap = new Apartment();
聽聽ap.setId(rs.getInt("id"));
聽聽ap.setAddress(rs.getString("address"));
聽聽ap.setBedrooms(rs.getInt("bedrooms"));
聽聽ap.setBathrooms(rs.getInt("bathrooms"));
聽聽ap.setPrice(rs.getInt("price"));
聽聽ap.setCity(rs.getString("city"));
聽聽ap.setProvince(rs.getString("province"));
聽聽return ap;
聽}
聽
聽
聽/**
聽 * Creates the where clause for the search SQL statement.
聽 * @param bedrooms
聽 * @param bathrooms
聽 * @param price
聽 * @return
聽 */
聽private String createSearchWhereClause(int bedrooms, int bathrooms, int price) {
聽聽String where = " where bedrooms >= " + bedrooms +
聽聽聽聽" and bathrooms >= " + bathrooms +
聽聽聽聽" and price < " + price;
聽聽return where;
聽}
}
8. search.jsp
聽 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
聽 <title>DWR Example</title>
聽聽 <style type="text/css" media="screen">
聽聽聽聽聽聽 @import url( style.css );
聽聽 </style>聽
聽
聽 <script src='dwr/interface/ApartmentDAO.js'></script>
聽 <script src='dwr/engine.js'></script>
聽 <script src='dwr/util.js'></script>
聽 <script>
聽
聽 function updateTotal() {
聽聽聽 $("resultTable").style.display = 'none';
聽聽聽 var bedrooms = document.getElementById("bedrooms").value;
聽聽聽 var bathrooms = document.getElementById("bathrooms").value;
聽聽聽 var price = document.getElementById("price").value;
聽聽聽 ApartmentDAO.countApartments(loadTotal, bedrooms, bathrooms, price);
聽 }
聽 function updateResults() {
聽聽聽 DWRUtil.removeAllRows("apartmentsbody");
聽聽聽 var bedrooms = document.getElementById("bedrooms").value;
聽聽聽 var bathrooms = document.getElementById("bathrooms").value;
聽聽聽 var price = document.getElementById("price").value;
聽聽聽 ApartmentDAO.findApartments(fillTable, bedrooms, bathrooms, price);
聽聽聽 $("resultTable").style.display = '';
聽 }
聽
聽 var getId = function(unit) { return unit.id };
聽 var getAddress = function(unit) { return unit.address };
聽 var getBedrooms = function(unit) { return unit.bedrooms };
聽 var getBathrooms = function(unit) { return unit.bathrooms };
聽 var getPrice = function(unit) { return unit.price };
聽聽聽
聽 function loadTotal(data) {
聽聽聽 document.getElementById("totalRecords").innerHTML = data;
聽 }
聽
聽 function fillTable(apartment) {
聽聽聽 DWRUtil.addRows("apartmentsbody", apartment, [ getId, getAddress, getBedrooms, getBathrooms, getPrice ]);
聽 }
聽
</script>
</head>
<body onload="updateTotal();">
<h2>Find an apartment to rent</h2>
<table border="0">
<form name="rentalForm">
聽 <tr width="400">
聽聽 <td width="100">City</td>
聽聽 <td width="300">Toronto</td>
聽 </tr>
聽 <tr>
聽聽 <td>Beds</td>
聽聽 <td>
聽聽聽 <select id="bedrooms" onchange="updateTotal()">
聽聽聽聽 <option value="1">1 or more</option>
聽聽聽聽 <option value="2">2 or more</option>
聽聽聽聽 <option value="3">3 or more</option>
聽聽聽聽 <option value="4">4 or more</option>
聽聽聽 </select>
聽聽 </td>
聽 </tr>
聽 <tr>
聽聽 <td>Baths</td>
聽聽 <td>
聽聽聽 <select id="bathrooms" onchange="updateTotal()">
聽聽聽聽 <option value="1">1 or more</option>
聽聽聽聽 <option value="2">2 or more</option>
聽聽聽聽 <option value="3">3 or more</option>
聽聽聽聽 <option value="4">4 or more</option>
聽聽聽 </select>
聽聽 </td>
聽 </tr>
聽 <tr>
聽聽 <td>Price</td>
聽聽 <td>
聽聽聽 <select id="price" onchange="updateTotal()">
聽聽聽聽 <option value="800">under $800</option>
聽聽聽聽 <option value="1000">under $1,000</option>
聽聽聽聽 <option value="1250">under $1,250</option>
聽聽聽聽 <option value="1500" selected="selected">under $1,500</option>
聽聽聽聽 <option value="1800">under $1,800</option>
聽聽聽聽 <option value="2000">under $2,000</option>
聽聽聽 </select>
聽聽 </td>
聽 </tr>
聽 <tr>
聽聽 <td colspan="2">
聽聽聽 <blockquote>
聽聽聽聽 Available apartments: <span id="totalRecords" style="font-weight:bold;"></span>
聽聽聽 </blockquote>
聽聽 </td>
聽 </tr>
</form>
</table>
<p><input type="button" value="Show results!" onClick="updateResults();"></p>
<div id="resultTable">
<h2>Results</h2>
聽<table border="1">
聽 <thead>
聽聽聽 <tr>
聽聽聽聽聽 <th width="40">Id</th>
聽聽聽聽聽 <th width="180">Address</th>
聽聽聽聽聽 <th width="60">Beds</th>
聽聽聽聽聽 <th width="60">Baths</th>
聽聽聽聽聽 <th width="60">Price</th>
聽聽聽 </tr>
聽 </thead>
聽 <tbody id="apartmentsbody">
聽 </tbody>
聽</table>
</div>
</body>
</html>
鐢變簬欏圭洰闇瑕?闇鍦ㄦ垜浠幇鏈夌殑struts銆乭ibernate宸ョ▼涓婇泦鎴恆jax鍔熻兘.欏圭洰緇勫喅瀹氫嬌鐢―wr.
鍒氬紑濮嬬爺絀禗wr.瑙夊緱鐪熺殑寰堜笉閿? 鍙渶寰堝皯閲忕殑浠g爜,灝辮兘鍦ㄧ幇鏈夌殑宸ョ▼涓婇泦鎴恆jax鎶鏈? 鏈熷緟Dwr鏈夋洿杈夌厡鐨勬槑澶╋紒
鍠滄Dwr鎶鏈殑IT鐣屾湅鍙嬪彲浠ヤ笌鏈漢鑱旂郴錛佹湜鎻愬嚭濂界殑鎰忚涓庡緩璁?
-vmargs
command line argument, which must follow all other Eclipse specific arguments. Thus, to increase the available heap memory, you would typically use:
eclipse -vmargs -Xmx<memory size>
with the <memory size>
value set to greater than "256M" (256 megabytes -- the default).
When using a Sun VM, you may also need to increase the size of the permanent generation memory. The default maximum is 64 megabytes, but more may be needed depending on your plug-in configuration and use. The maximum permanent generation size is increased using the -XX:MaxPermSize=<memory size> argument:
This argument may not be available for all VM versions and platforms; consult your VM documentation for more details.
eclipse -vmargs -XX:MaxPermSize=<memory size>
Note that setting memory sizes to be larger than the amount of available physical memory on your machine will cause Java to "thrash" as it copies objects back and forth to virtual memory, which will severely degrade your performance.
鍦╡clipse瀹夎鏍圭洰褰曚笅錛岀敤姝ゅ懡浠?聽聽聽 eclipse.exe -vmargs -Xms256M -Xmx512M
聽聽聽聽聽聽聽聽 濡傛灉璇存垜榪欎袱騫村湪Sun鍏徃浣滀簡鍝簺瀵逛腑鍥藉紑鍙戜漢鍛樻湁鐩婄殑浜嬬殑璇濓紝鎴戞兂Java API鏂囨。涓枃鐗堟鏃犵枒闂殑搴旇綆楃涓涓傛垜闈炲父娓呮浠嶇劧鏈変紬澶氬紑鍙戜漢鍛樺潥鎸佽涓轟竴涓ソ鐨勭▼搴忓憳搴旇瀹屽叏鍙傝冭嫳鏂囩増鐨勬枃妗o紝浣嗘槸鎴戝潥淇¤鏂囨。鐨勪腑鏂囩増鏈夊叾瀛樺湪鐨勬剰涔夛紝鍥犱負 Java浣滀負涓縐嶇▼搴忚璁¤璦錛屾垜浠笇鏈涜兘澶熸湁鏇村鐨勫紑鍙戜漢鍛樷斺旇屼笉浠呬粎鏄偅浜涜兘澶熺啛緇冮槄璇昏嫳璇殑娓呭崕鍖楀ぇ姣曚笟鐢熲斺旀潵浣跨敤瀹冿紝鎺屾彙瀹冿紝綺鵑氬畠銆?/font>
涔熷彲浠ヨ繖涔堣錛孞ava璇█鐨勫墠閫旓紝鏇村鍙栧喅浜庤崏鏍癸紝鑰屼笉鏄簿鑻便?/font>