<!doctype html public "-//w3c/dtd HTML 4.0//en">
<html>
<head><title>Employee lookup</title></head>

<%@ page 
  info="EmpBean lookup example"
  contentType="text/html"
  import="java.lang.Integer, javax.naming.*, javax.ejb.*, weblogic.common.*,
          examples.intro.Emp, examples.intro.EmpBeanHome"
%>
<body>
<font face="Helvetica">
<h1><font color="#FF0000">Employee Lookup</font></h1>

<hr>
<form action=<%= request.getRequestURI() %> method="post">
<table border=0 cellspacing=5 align=center>
<tr>
  <td>Search by</td>
  <td><select name=searchType>
  <option value=1>Employee number</option>
  <option selected value=2>Employee name</option>
  <option value=3>Name like ('%' is wildcard)</option>
  </select>
  </td>
</tr>
<tr>
  <td>Search for</td>
  <td><input type=text name=criteria size=10 maxlength=10></td>
</tr>
<tr>
  <td align=center colspan=2><input type=submit value="Go">
  </td>
</tr>
</table>
</form>
<p>

<%

    if (request.getParameter("searchType") != null 
	&& request.getParameter("criteria") != null) 
    {
      int searchType = Integer.parseInt(request.getParameter("searchType"));
      String criteria = request.getParameter("criteria");
      Emp emp = null;
      Enumeration emps = null;
      try {
        Context ctx = new InitialContext();
        EmpBeanHome home = (EmpBeanHome) ctx.lookup("EmpBeanHome");
        switch (searchType) {
        case 1: // by employee number
          emp = (Emp) home.findByEmpno(Integer.parseInt(criteria));
          break;
        case 2: // by Employee name
          emps = home.findByName(criteria.toUpperCase());
          break;
        case 3: // by name like
          emps = home.findByNameLike(criteria.toUpperCase());
          break;
        default:
        }

        if (emp != null || emps != null) {
          // we have data
%>

<hr>
<h2>Search Results</h2>
<table border=1 align=center>
<tr>
  <th>Employee number</th>
  <th>Name</th>
  <th>Title</th>
  <th>Manager</th>
  <th>Hire date</th>
  <th>Salary</th> 
  <th>Commission</th>
  <th>Department</th>
</tr>

<% 
       }
       if (emp != null) {
         out.print(emp.htmlToPrint());
       }
       else {
         while (emps.hasMoreElements()) {
           emp = (Emp) emps.nextElement();
           out.print(emp.htmlToPrint());
         }
       }
%>
</table>

<%
   }
      catch (NumberFormatException nfe) {
        out.print("<p>Error attempting to convert " +
                  criteria + " to an integer.");
      }
      catch (Exception e) {
        out.print("<p>Exception: " + e.getMessage());
      }
    }
%>
<p>
<hr>
<center>
<p>Executed by 
<%= application.getServerInfo() %>.<br>
Copyright 1999-2000 &copy; BEA Systems, Inc. 
All Rights Reserved. 
</center>
</font>
</body>
</html>




