The next requirement for many JSP pages is to be able to use request parameters to configure the behavior of the page. Using the Agency case study as an example, you will develop a simple JSP to display the contents of a named database table.
The first step is to define a simple form to allow the user to select the table to display. Listing 13.7 shows a simple form encoded as a JSP.
Although the form in Listing 13.7 contains only HTML, it is convenient to treat it as a JSP. You can define an alias for this page and deploy it to the same Web resource location as the JSP that will display the table. This will simplify the application deployment and Web site management administration. The form component of the page is set to invoke the JSP called table in the current Web application (see line 4).
You will need to add this JSP to the simple Web application and define an alias of /tableForm to use it.
The actual JSP to display the table is shown in Listing 13.8.
The JSP in Listing 13.8 uses the implicit JSP variable called request to access the ServletRequest object (see line 3). The request parameters are retrieved by using the getParameter() method on the request object. The rest of this JSP simply creates an instance of the agency Session bean and uses the select() method to retrieve the table data. The data is formatted as an HTML table and output using the implicit JspWriter variable called out.
You will need to add this JSP to the simple web application and define an alias of /table to use it. Because the Web application file already contains an EJB Reference to the agency Session bean (from the name.jsp example in Listing 13.6), you do not need to define this EJB Reference again. If you deploy this Web component in a different Web application, you will need to add the EJB reference shown previously in Figure 13.9.
13.59.32.1