createAddress.jsp
上传用户:dinglihq
上传日期:2013-02-04
资源大小:99958k
文件大小:2k
源码类别:

Java编程

开发平台:

Java

  1. <%@ page contentType="text/html; charset=GBK" %>
  2. <%@ page language="java" %>
  3. <%@ page import="javax.naming.InitialContext" %>
  4. <%@ page import="cmpsample.*" %>
  5. <html>
  6. <head><title>Chapter 11 CMP 2.0 Sample Example </title></head>
  7. <body bgcolor="white">
  8. <center>
  9. <h2>Chapter 11 CMP 2.0 AddressEJB - Create an Address </h2>
  10. <p>
  11. <form method="post" action="/WebApp/createAddress.jsp">
  12. <table border=10>
  13.   <tr>
  14.     <td>Student ID: </td>
  15.     <td><input type="text" name="id" size="11" value=""></td>
  16.   </tr>
  17.   <tr>
  18.     <td>Address ID: </td>
  19.     <td><input type="text" name="addressID" size="11" value=""></td>
  20.   </tr>
  21.   <tr>
  22.     <td>Street Name: </td>
  23.     <td><input type="text" name="streetName" size="25" value=""></td>
  24.   </tr>
  25.   <tr>
  26.     <td>City Name: </td>
  27.     <td><input type="text" name="city" size="15" value=""></td>
  28.   </tr>
  29.   <tr>
  30.     <td>State Name: </td>
  31.     <td><input type="text" name="state" size="2" value=""></td>
  32.   </tr>
  33.   <tr>
  34.     <td>Zip Code: </td>
  35.     <td><input type="text" name="zip" size="5" value=""></td>
  36.   </tr>
  37. </table>
  38. <p>
  39. <input type="submit" name="submit" value="Submit">
  40. <p>
  41. </form>
  42. <%
  43. String id = request.getParameter("id");
  44. String AddressID = request.getParameter("addressID");
  45. String StreetName = request.getParameter("streetName");
  46. String CityName = request.getParameter("city");
  47. String StateName = request.getParameter("state");
  48. String ZipCode = request.getParameter("zip");
  49. if (id != null && !"".equals(id)) {
  50.     try {
  51.         InitialContext ic = new InitialContext();
  52.         Object o = ic.lookup("Address");
  53.         AddressHome home = (AddressHome) o;
  54.         Address address = home.create(id, AddressID, StreetName, CityName, ZipCode, StateName);
  55. %>
  56. New Address created: <br>
  57. <%=address.getStreet()%>,
  58. <%=address.getCity()%>
  59. </p>
  60. <a href = "/WebApp/searchAddress.jsp">SEARCH</a></p>
  61. <%
  62.     } catch(Exception e) {
  63.         e.printStackTrace();
  64.         out.println("Create new Address FAILED : " + e.toString());
  65.     }
  66. }
  67. %>
  68. <hr>
  69. [<a href="/WebApp/index.html">HOME</a>]
  70. </center>
  71. </body>
  72. </html>