Blog / Develop the Code to Call Our Web Service Operation DeleteFaculty() – Develop Java Web Services to Access Databases

Develop the Code to Call Our Web Service Operation DeleteFaculty() – Develop Java Web Services to Access Databases

Develop the Code to Call Our Web Service Operation DeleteFaculty() – Develop Java Web Services to Access Databases


9.13.3   Develop the Code to Call Our Web Service Operation DeleteFaculty()

Open our Web-based client project WebClientFaculty _ UpdtDelt and double-click on the FacultyMBean.java in the Projects window to open this managed bean class file. Enter the code shown in Figure 9.66 into this class file to generate our Delete _ Faculty() method.

Let’s have a closer look at this piece of new added code to see how it works.

A. First a local integer variable, numDeleted, is declared and initialized to 1. This variable is used to hold our data delete operation result.

B. A try-catch block is used to perform the calling of our Web service operation DeleteFaculty() to perform this faculty data delete action. First a new Web service instance service is created based on our Web service class WebServiceFaculty _ Service. Then the getWebServiceFacultyPort() method is executed to get the current port used by our Web service. This port is returned and assigned to a new port instance, port.

FIGURE 9.66  The generated code for the Delete_Faculty() method.

C. The deleteFaculty() operation in our Web service is called with the original faculty name as the argument. The execution result of this faculty data delete is returned and assigned to the local Boolean variable delete.

D. If the returned Boolean variable delete is false, which means that the data delete fails, a System.out.println() method is used to indicate this situation, and a zero is returned to the client project to indicate this situation.
E. The catch block is used to catch any possible exception during the data delete process. A zero is returned to the client project if any exception really occurs.
F. Finally the local variable, numDeleted, is returned to the client project indicate a suc-cess of the data delete operation.

Next let’s add some code into our Control class FacultyProcess.jsp page to coordinate the Model class or Java Bean to perform related data update or delete actions.

Angela Gaffney

  • 0

Leave a Reply

Your email address will not be published. Required fields are marked *


                Copyright © 2024 Saucierlight.com. All Rights Reserved.