8.1.4 Using the JSP Implicit Object Session for Java Web Applications
As we mentioned in Section 8.1.2, the session is a JSP implicit object used to help developers build professional Java Web applications. “Implicit” means that those objects, including the session object, can be created automatically when a new JSP is executed. The specific property of using a session object is that you can save user data in some Web pages and retrieve it from other Web pages. This provides a great and convenient way to transfer data between clients and clients and also between clients and a server.
In this section, we will use this session object to help us to build our Faculty page to query and display the desired faculty information from the Faculty Table in our sample database. The structure or architecture of using the session object to coordinate the data query from the Faculty Table is shown in Figure 8.11.
Basically, this structure is identical to that we discussed in the last section, and the only differ-ence is that we use a new Java help class file, FacultyBean.java, that is not a real Java Bean class but is very similar to a JavaBean. The reason we do this is that we do not want to have a big jump between the help class and JavaBean to make this design difficult.
FacultyPage.jsp, our Web client page, is shown in Figure 8.12. Because of its complex HTML and JSP code, we will leave the building and coding of this page to our real project later. In

FIGURE 8.11 The architecture of using session objects in Web applications.

FIGURE 8.12 Preview of the FacultyPage.jsp page.
fact, we need to use Microsoft Office Publisher 2007 to build a FacultyPage.html file first and then convert it to a FacultyPage.jsp file. Now we just assume that we have built this page and want to use it in our Faculty Table query process.
Now let’s modify FacultyPage.jsp to use a session object to perform data storage and retrieval functions between this page and the help class file FacultyQuery.jsp.
8.1.4.1 Modify the FacultyPage JSP File to Use the Session Object
Perform the modifications shown in Figure 8.13 to the FacultyPage.jsp file to use the session object to store and pick up data between client pages. All modified code is in bold.
In step A, we add an action attribute to forward all information collected from this page to our model and controller page, FacultyQuery.jsp, that will call our FacultyBean file to perform the faculty data query process.
Starting from step B until step H, we use the embedded JSP code to assign the real queried faculty columns from our Faculty Table to the value tag of each text field in the Facultypage. jsp using the getAttribute() method of the session class. In this way, as long as the que-ried faculty row has any change, the modification will be immediately updated and reflected to each text field in our FacultyPage.jsp page. In this way, a direct connection or binding between the text fields in our Facultypage.jsp page and the queried Faculty columns in our help class is established.
Now let’s take a look at our model and controller page, FacultyQuery.jsp.
