PROCEDURE A(errbuf OUT VARCHAR2,
retcode OUT VARCHAR2,
p_1 IN VARCHAR2,
p_2 IN NUMBER);
end XXXX_X_XXX_PKG ;
注:包头ä¸å£°æ˜Žä¸€ä¸ªProcedure, 包体ä¸å£°æ˜Žä¸€ä¸ªä¸»Procedure(例如: A),多个从Procedure(一般是些共用方æ³?(例如åQšB), 注æ„包体ä¸Procedure实现‹Æ¡åºåQŒåº”先声明B ,
在A˜q‡ç¨‹é‡Œï¼Œå¯ä»¥è°ƒç”¨B.
æ–ÒŽ(gu¨©)³•äº?
包头:
create or replace package XXXX_X_XXX_PKG is
PROCEDURE A(errbuf OUT VARCHAR2,
retcode OUT VARCHAR2,
p_1 IN VARCHAR2,
p_2 IN NUMBER);
PROCEDURE B( retcode OUT VARCHAR2,
p_1 IN VARCHAR2,);
end XXXX_X_XXX_PKG ;
包体ä¸?æ¤æ—¶Aå¯ä»¥ç›´æŽ¥å¼•用B,ä¸è®ºå®žçް‹Æ¡åº.
 <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
  实现了ServletContextListerer接å£çš„ç±»
  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ã€hibernate工程上集æˆajax功能.™å¹ç›®¾l„决定ä‹É用Dwr.
åˆšå¼€å§‹ç ”½I¶Dwr.觉得真的很ä¸é”? åªéœ€å¾ˆå°‘é‡çš„代ç ,ž®Þpƒ½åœ¨çŽ°æœ‰çš„å·¥ç¨‹ä¸Šé›†æˆajax技æœ? 期待Dwr有更辉煌的明天ï¼
喜欢Dwr技术的IT界朋å‹å¯ä»¥ä¸Žæœ¬ähè”ç³»åQ望æå‡ºå¥½çš„æ„è§ä¸Žå¾è®?