searchaddress.jsp

来自「100多M的J2EE培训内容」· JSP 代码 · 共 62 行

JSP
62
字号
<%@ 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>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?