ejbean.setFirstName(getBean().getFirstName()); ejbean.setLastName(getBean().getLastName()); ejbean.setEmail(getBean().getEmail());

}

Modifying CustomerXSLServlet

The changes to the CustomerXSLServlet are in two directions. Changes to the doPost method of the servlet that enables storing new customer records in the database. While the changes to the doGet method of the servlet enables retrieving customer information from the database, based on a membership input value. To achieve our target, we need to perform the following to the CustomerXSLServlet:

1.Modify the servlet’s import statements. Add the following imports:

import registration.*; import javax.ejb.*;

2.Now in the doPost method, invoke the CustomerXML create method, after setting up all property values. You have to catch the exceptions that might be thrown, and return to the input form. See Example 10-14.

Example 10-14 CustomerXSLServlet doPost source code

public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException

{

CustomerXML xml = getCustomerXML();

xml.setMembership(new Long(request.getParameter("membership"))); xml.setFirstName(new java.lang.String(request.getParameter("firstName"))); xml.setLastName(new java.lang.String(request.getParameter("lastName"))); xml.setEmail(new java.lang.String(request.getParameter("email")));

try{

//Write to EJB. xml.create();

}catch(CreateException crateEx){ showPage(mainStylesheet, response);

}

showPage(resultStylesheet, response);

}

252 The XML Files: Development of XML/XSL Applications Using WebSphere Studio

Page 268
Image 268
IBM Version 5 manual Modifying CustomerXSLServlet, Example 10-14 CustomerXSLServlet doPost source code