title: How to read and pass data from servlet to JSP
body: <p>A question about read and pass data from servlet to JSP</p>
  
  <p>I want to create a Java EE project. Totally, it has 5 files in this project. </p>
  
  <ul>
  <li>JSP Files: EmployeeInfo.jsp, EmployeeDetails.jsp</li>
  <li>Servlets: EmployeeRegistrationServlet, EmployeeSearchServlet</li>
  <li>Bean: Employee</li>
  </ul>
  
  <p><strong>EmployeeInfo.jsp</strong> file that gets either Employee Id or Employee Information. It have two Submit buttons. If user wants to search an Employee, an ID would be entered and it will call EmployeeSearchServlet, if user wants to add new Employee information, then EmployeeRegistrationServlet will be called with customer information entered. Here is the code:</p>
  
  <p><strong>EmployeeSearchServlet</strong> is supposed to search an employee with employee id that was entered by the end user. The job of the servlet is to find particular employee within a collection. Once the employee is found, the flow will be forwarded to EmployeeDetails.jsp.</p>
  
  <p><strong>EmployeeRegistrationServlet</strong> is supposed to add employees into a collection where store employees in memory.</p>
  
  <p>If an employee is found, details of employee will be displayed on EmployeeDetails.jsp. 
  If a new employee is added, details of employee will be displayed on EmployeeDetails.jsp.</p>
  
  <p>Here is my EmployeeInfo.jsp</p>
  
  <pre><code>&lt;body&gt;
  &lt;h1 align="center"&gt;Employee Information&lt;/h1&gt;
  &lt;!--Form of find employee by employeeID --&gt;
  &lt;form action="EmployeeSearchServlet" method="POST"&gt;
    &lt;fieldset&gt;
      &lt;legend&gt;Find Employee&lt;/legend&gt;
      Employee ID: &lt;input type="text" name="findEmployeeID"&gt;&lt;br&gt;
      &lt;input type="submit" name="findEmployeeSubmit" value="Find Employee"&gt;
    &lt;/fieldset&gt;
  &lt;/form&gt;
  &lt;p&gt;&lt;/p&gt;
  &lt;!--Form of add employee--&gt;
  &lt;form action="EmployeeRegistrationServlet" method="POST"&gt;
    &lt;fieldset&gt;
      &lt;legend&gt;Employee Information&lt;/legend&gt;
          &lt;table&gt;
              &lt;tr&gt;
                  &lt;td&gt;Employee ID (key)*: &lt;/td&gt;
                  &lt;td&gt;&lt;input type="text" name="employeeID"&gt;&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td&gt;First Name:* &lt;/td&gt;
                  &lt;td&gt;&lt;input type="text" name="firstName"&gt;&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td&gt;Last Name:* &lt;/td&gt;
                  &lt;td&gt;&lt;input type="text" name="lastName"&gt;&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td&gt;Email: &lt;/td&gt;
                  &lt;td&gt;&lt;input type="text" name="email"&gt;&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td&gt;Phone: &lt;/td&gt;
                  &lt;td&gt;&lt;input type="text" name="phone"&gt;&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td&gt;Hire Date: &lt;/td&gt;
                  &lt;td&gt;&lt;input type="text" name="hireDate"&gt;&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td&gt;Manager ID: &lt;/td&gt;
                  &lt;td&gt;&lt;input type="text" name="managerID"&gt;&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td&gt;Department ID: &lt;/td&gt;
                  &lt;td&gt;&lt;input type="text" name="departmentID"&gt;&lt;/td&gt;
              &lt;/tr&gt;
          &lt;/table&gt;
      &lt;input type="submit" name="addEmployeeSubmit" value="Add Employee"&gt;
    &lt;/fieldset&gt;
  &lt;/form&gt;
  
  &lt;/body&gt;
  </code></pre>
  
  <p>Here is my Employee bean.</p>
  
  <pre><code>public class Employee {
      private String employeeID;
      private String firstName;
      private String lastName;
      private String email;
      private String phoneNumber;
      private String hireDate;
      private String managerID;
      private String departmentID;
  
      public Employee(String newEmployeeID, 
              String newFirstName, 
              String newLastName, 
              String newEmail,
              String newPhoneNumber,
              String newHireDate,
              String newManagerID,
              String newDepartmentID){
          this.employeeID = newEmployeeID;
          this.firstName = newFirstName;
          this.lastName = newLastName;
          this.email = newEmail;
          this.phoneNumber = newPhoneNumber;
          this.hireDate = newHireDate;
          this.managerID = newManagerID;
          this.departmentID = newDepartmentID;
      }
  
      public void setEmployeeID(String newEmployeeID){
          this.employeeID = newEmployeeID;
      }
  
      public void setFirstName(String newFirstName){
          this.firstName = newFirstName;
      }
  
      public void setLastName(String newLastName){
          this.lastName = newLastName;
      }
  
      public void setEmail(String newEmail){
          this.email = newEmail;
      }
  
      public void setPhoneNumber(String newPhoneNumber){
          this.phoneNumber = newPhoneNumber;
      }
  
      public void setHireDate(String newHireDate){
          this.hireDate = newHireDate;
      }
  
      public void setManagerID(String newManagerID){
          this.managerID = newManagerID;
      }
  
      public void setDepartmentID(String newDepartmentID){
          this.departmentID = newDepartmentID;
      }
  
  public String getEmployeeID() {
      return employeeID;
  }
  
  public String getFirstName() {
      return firstName;
  }
  
  public String getLastName() {
      return lastName;
  }
  
  public String getEmail() {
      return email;
  }
  
  public String getPhoneNumber() {
      return phoneNumber;
  }
  
  public String getHireDate(){
      return hireDate;
  }
  
  public String getManagerID(){
      return managerID;
  }
  
  public String getDepartmentID(){
      return departmentID;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>here is my  EmployeeRegistrationServlet</p>
  
  <pre><code>@WebServlet("/EmployeeRegistrationServlet")
  public class EmployeeRegistrationServlet extends HttpServlet {
      private Map&lt;String,Employee&gt; employees;
      @Override
      public void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
          String employeeID = request.getParameter("employeeID").trim();
          String firstName = request.getParameter("firstName").trim();
          String lastName = request.getParameter("lastName").trim();
          String email = request.getParameter("email").trim();
          String phone = request.getParameter("phone").trim();
          String hireDate = request.getParameter("hireDate").trim();
          String managerID = request.getParameter("managerID").trim();
          String departmentID = request.getParameter("departmentID").trim();
          employees = new HashMap&lt;String,Employee&gt;();
          Employee newAdd = new Employee(employeeID, firstName, lastName, email, phone, hireDate, managerID, departmentID);
  
          request.getRequestDispatcher("../../../../WebContent/EmployeeDetail.jsp").forward(request,response);
      }
  }
  </code></pre>
  
  <p>My question is how to use EmployeeDetail.jsp read bean object passed from EmployeeRegistrationServlet? And how to Find an employee by searching the employee ID?
  Please give me some suggestions. Thanks a lot.</p>