Servlet code.

POWER JAVA
A Pattern for Building Powerful JSPs
Donald Bell, Sérgio Henrique Monteiro Da Silva, and John Shelton
Listing 1. Servlet code.


public void doPost(HttpServletRequest request, HttpServletResponse response)
{
  // Default the user back to the entry page.
  String sRedirect = EMPLOYEE_JSP;

  // Get the correct instance of the Translator
  EmployeeTranslator etTrans = EmployeeTranslator.getInstance(request);

  // Now that we have an instance of the Translator
 etTrans.processForm(request);
  // Since there could be some kind of possible
  if (etTrans.getErrors() == null)
  {
    // Logic for getting correct version of Employee
    Employee emplNewEmployee = null;
    if (etTrans.isNewEmployee() == true)
    {
       // Create new Employee
    }
    else
    {
       // Get existing employee
    }
    // Sync the Employee object values to values in the submitted
    //form.
    etTrans.syncModelToGui(emplNewEmployee);

    // Make sure no errors occurred
    if (etTrans.getErrors() == null)
    {
      // Commit the employee info and then set the redirect to the
      // correct following page
      sRedirect = EMPLOYEE_CONFIRMATION;
    }
  }

  // Redirect the Web site visitor to the correct page.
  try
  {
    response.sendRedirect(sRedirect);
  }
  catch (Exception e)
  {
    // Error logic
  }
}

Featured

Most   Popular
Upcoming Events

AppTrends

Sign up for our newsletter.

Terms and Privacy Policy consent

I agree to this site's Privacy Policy.