Build the Help Class FacultyBean 2 – Develop Java Web Applications to Access Databases

The operational sequence and data transformation structure of the Faculty Name are shown in Figure 8.16, where the faculty name is used as an example to illustrate how to transfer data between the client and the help class. The operational sequence is:

1) First the desired faculty name is entered by the user into the Faculty Name text field on the FacultyPage.jsp page. This piece of data will be transferred to the FacultyQuery. jsp page when the Select button is clicked by the user.

2) In the FacultyQuery.jsp page, the getParameter() method is used to pick up the transferred Faculty Name.

3) Then the help method QueryFaculty() in the help class FacultyBean is called to query a matching faculty record from the Faculty Table based on the transferred faculty name, fname.

4) When the getter() method in the FacultyBean class is executed, the queried faculty name is returned to the FacultyQuery.jsp page.
5) One of session methods, setAttribute(), is called to stored the queried faculty name in the JSP implicit object session.

FIGURE 8.16   The operational sequence and data transfer structure using the session object.

FIGURE 8.17   The run status of FacultyPage.jsp.

6) The getAttribute(“facultyName”) method that is assigned to the value tag of the FacultyName text field will pick up the queried faculty name and display it in the text field in step 7.

By referring to Figure 8.16, we can get a clear and complete picture of the data storage and trans-fer between different pages.

Now if you compile and run these three files, FacultyPage.jsp, FacultyQuery.jsp and FacultyBean.java, you can get the start page shown in Figure 8.17. Enter a desired faculty name

FIGURER 8.18   The run result of FacultyPage.jsp.

such as Ying Bai into the Faculty Name text field and click on the Select button. The run result is shown in Figure 8.18.

As we mentioned at the beginning of this chapter, Java EE provides a set of powerful tools and support to Java Web applications to access and manipulate databases. One of the most important components provided by Java EE is the Java bean that works as a separate component to perform database-related operations and business logic. By combining JavaServer Faces techniques and Java beans, a professional Java Web database application can be divided into two separate parts: the GUI that is built with JSF tags in JavaServer Pages isused for data presentation and displaying results, and Java managed beans are used for database-related operations and business logic. By dividing a Web application into these two sections, it greatly reduces the development efforts and complexities in code development and organization of the whole application.

Now let’s take care of using Java beans technology for Java Web applications.

Leave a Comment



                    Blog, Contribute ,Privacy,Terms of Use,Trademarks,© estherknow 2024