Now let’s build our LogInQuery.jsp page, which works as a part of the server, to receive and handle the Form data, including the login information sent by the index.jsp page. Figure 8.9 shows the code for this page. Let’s have a closer look at this piece of code to see how it works.
A. A JSP directive tag is to indicate that this page uses the Java language and is a JSP file.
B. Some local variables and objects are declared first. The string variable nextPage is used to hold the URL of the next page, and lquery is a new instance of our Java help class, LogInQuery, we built at the beginning of this section.
C. The getParameter() method is used to pick up the login information entered by the user in the index.jsp page. The collected login information, including the username and password, is assigned to two local string variables, u _ name and p _ word, respectively.
D. The checkLogIn() method defined in our Java help class file is called to perform the database query and the login matching processing. The collected login information is used as arguments and passed into this method. The run result of this method is a string, and it is assigned to the local string variable result.
E. An if block is used to check the run result of the checkLogIn() method. The program will be forwarded to a success page (Selection.jsp) if the login process is successful.
F. Otherwise, an error message is printed to indicate that the login process failed.
G. A JSP forward directive is used to direct the program to the next page.
In summary, to use a JavaServer Page to assist a Java Web application, the following components should be considered and used:
1) The whole Web application can be divided into two parts:
a. The JDBC- and database processing–related functions and business logic—Java help class file (LogInQuery.java).
b. The user data input and run result output functions—HTML or JavaServer Pages (index.jsp and LogInQuery.jsp).
2) The relationships between these three pages are:
a. index.jsp, which runs on the client side, works as a starting or home page as the Web application runs, and it is used to collect user information and send it to the Web server.
b. LogInQuery.jsp, which can be considered a part of the application server and runs on the server side, provides information passing or transformation functions between the home page and other target pages to collect user information, call the Java help class to perform data and business logic processing and direct the program to the different target pages based on the data processing results.
c. The Java help class file LogInQuery.java, which provides the JDBC and database processing functions and business logic processing abilities, works as an intermediate layer between the server and clients to support the previoustwo JSP files. Since this help class file will be called by LogInQuery.jsp, it also belongs to the server-side software.
These components and their relationships are illustrated in Figure 8.10.
Compared with our first Java Web application that utilized the Java Servlet and HTML page, the Web application that used the JavaServer Pages techniques has great improvements in simplifica-tion of data collection and processing by using different function-related pages and a help class file. However, one defect is that JDBC- and database-related functions make the Java help class file LogInQuery.java very complicated because too many database-related functions must be involved and executed, such as loading database drivers, connecting to the database, creating query-related objects, building the data query and collecting the queried results. All of these operations make this file longer and increase the complexity of operations. A good solution to this is to use the JSP Sessions to simplify these operations and make the file short and simple.

FIGURE 8.10 The components and their relationships in a JSP Web application.