searchRoster.jsp
资源名称:某公司的java培训教材 [点击查看]
上传用户:dinglihq
上传日期:2013-02-04
资源大小:99958k
文件大小:2k
源码类别:
Java编程
开发平台:
Java
- <%@ page contentType="text/html; charset=GBK" %>
- <%@ page language="java" %>
- <%@ page import="java.util.ArrayList" %>
- <%@ page import="java.util.*" %>
- <%@ 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 - RosterEJB - Search for a roster entity</h2>
- Search for a Roster:
- <p>
- <form method="get" action="/WebApp/searchRoster.jsp">
- Search by
- <select name="searchCriteria">
- <option value="rosterID" selected>Roster ID
- <option value="scheduleID">schedule ID
- <option value="studentID">Student ID
- </select>
- <input type="text" name="searchText" size="25">
- <p>
- <input type="submit" value="Search">
- </form>
- <%
- String text = request.getParameter("searchText");
- String criteria = request.getParameter("searchCriteria");
- if (text != null && !"".equals(text)) {
- try {
- InitialContext ic = new InitialContext();
- Object o = ic.lookup("Roster");
- RosterHome home = (RosterHome) o;
- Collection Rosters = new ArrayList();
- if ("rosterID".equals(criteria)) {
- try {
- Roster roster = home.findByPrimaryKey(text);
- Rosters.add(roster);
- } catch (ObjectNotFoundException ex) {}
- }
- else if ("scheduleID".equals(criteria)) {
- Rosters = home.findByScheduleID(text);
- }
- else if ("studentID".equals(criteria)) {
- Rosters = home.findByStudentID(text);
- }
- else {
- }
- %>
- Results: <%=Rosters.size()%><p>
- <%
- Iterator it = Rosters.iterator();
- while(it.hasNext())
- {
- Roster rost = (Roster) it.next();
- %>
- <p>
- <b> Roster Information </b><br>
- RosterID: <%=rost.fetchRosterID()%>
- ScheduleID: <%=rost.fetchScheduleID()%>
- StudentID: <%=rost.fetchStudentID()%>
- <p>
- <%
- }
- } catch(Exception e) {
- e.printStackTrace();
- out.println(e.toString());
- }
- }
- %>
- <hr>
- [<a href="/WebApp/index.html">HOME</a>]
- </center>
- </body>
- </html>