QUERY THE COURSE TABLE USING JAVASERVER PAGES AND JSP IMPLICIT SESSION OBJECT 2 – Develop Java Web Applications to Access Databases

Two methods can be used to add the Details button; one is to use a piece of JSP code and add it directly into the Course.jsp file, and the other is to use Microsoft Office Publisher 2007 to graphically add the button to the Course.html page and then save it as a JSP page. Here we try to use the first way to add this button, since it is easier.

Open this page by double-clicking on it in the Projects window, and perform the modifica-tions shown in Figure 8.98 to this page. All modified code is in bold. Let’s have a closer look at this piece of modified code to see how it works.

A. Since we need to use the JSTL core with embedded C tags in this page to dynamically
populate the CourseList box, we need to include that library first.
B. Use this piece of code to replace the original code for this tag (around line 321). The purpose of this piece of code is to populate all fetched course _ id values in the CourseList box for a selected faculty member by the user. All course _ id values will be retrieved and collected from our database and stored in a HashMap list object later in our Java Bean class. The name of that HashMap object is c _ course, which contains two columns, key and value. The former represents a key for a course _ id, and the latter is the course _ id value. The syntax ${} is used to store a value for a vari-able in JSTL C tags. A tag is used for course _ id population purposes.

C. Copy this piece of code and add it directly under the tag. The purpose of this piece of code is to add a Details button just under the CourseList box in the Course.jsp page to enable users to click it to trigger an event to get details for a selected course _ id from the CourseList box by the user.
D. From step D through step I, we use the embedded JSP code to assign the selected and que-ried course columns from our Course Table to the value tags of the associated text field in Course.jsp using the getAttribute() method of the session class. In this way, if a queried course row has any change, it will be immediately reflected in each text field in our Course.jsp page. Thus, a direct binding between the text fields in our Course.jsp page and the queried course columns in our Java Bean class is established.
name attribute is added to each Submit button tag. This attribute isJ.InstepsJtoN,a very important, since we need to use it to identify each submit button on the next page, our controller page, CourseProcess.jsp, using the getParameter() method of the request object to direct control to the different pages to handle different data query and data manipulation actions in the Course Table in our sample Oracle database, CSE _ DEPT.

FIGURE 8.98   The modified code for the Course.jsp page.

O. Similar to steps D through I, the facultyName variable in our Java Bean class is bound to this FacultyNameField in this page to set a connection between that variable and the TextField on this page.

A view of the modified Course.jsp page is shown in Figure 8.99. Now let’s take a look at our controller page, CourseProcess.jsp.

Related Posts

Leave a Reply

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