searchAddress.jsp
资源名称:某公司的java培训教材 [点击查看]
上传用户:dinglihq
上传日期:2013-02-04
资源大小:99958k
文件大小:1k
源码类别:
Java编程
开发平台:
Java
- <%@ page contentType="text/html; charset=GBK" %>
- <%@ page language="java" %>
- <%@ page import="java.util.ArrayList" %>
- <%@ page import="java.util.Collection" %>
- <%@ page import="javax.ejb.ObjectNotFoundException" %>
- <%@ page import="javax.naming.InitialContext" %>
- <%@ page import="cmpsample.*" %>
- <html>
- <head><title>Chapter 11 CMP 2.0 Sample Example </title></head>
- <body bgcolor="white">
- <center>
- <h2>Chapter 11 CMP 2.0 AddressEJB - Search for an address entity</h2>
- <p>
- <form method="get" action="/WebApp/searchAddress.jsp">
- <input type="text" name="searchText" size="25">
- <p>
- <input type="submit" value="Search">
- </form>
- <%
- String text = request.getParameter("searchText");
- Address address = null;
- if (text != null && !"".equals(text)) {
- try {
- InitialContext ic = new InitialContext();
- Object o = ic.lookup("Address");
- AddressHome home = (AddressHome) o;
- try {
- address = home.findByPrimaryKey(text);
- } catch (ObjectNotFoundException ex) {}
- %>
- Results: <p>
- <%
- if (address != null) {
- %>
- Address [<%=address.getAddressID()%>] :
- <%=address.getStreet()%>, <%=address.getCity()%>
- <p>
- <%
- } else {
- %>
- Address [<%=text%>] Not Found.
- <%
- }
- } catch(Exception e) {
- e.printStackTrace();
- out.println(e.toString());
- }
- }
- %>
- <hr>
- [<a href="/WebApp/index.html">HOME</a>]
- </center>
- </body>
- </html>