Learn Java for Web Development

(Tina Meador) #1
CHAPTER 2: Building Web Applications Using Servlets and JSP 83

We will create two JSPs, shown in Listing 2-21 and Listing 2-22, to illustrate the use of the


action.

Listing 2-21. main.jsp


1.
2.
3.
4.
5.<%out.print("Inside main.jsp"); %>

6.
7.
8.


   Line 6: Uses the <jsp:include> to include the target JSP page (sub.jsp)

Listing 2-22. sub.jsp


1.
2.
3.
4.
5.<%out.print("Inside sub.jsp"); %>

6.
7.


Figure 2-28 shows the output when main.jsp is accessed.


Figure 2-28. Using the action


The Action


The action is used to forward the current request to another resource such as a static
page, a JSP page, or a servlet. The syntax for the action is as follows:



We will use the two JSPs created in the previous section to illustrate the use of the
action as illustrated in the Listing 2-23 and 2-24.

Free download pdf