Java Reference
In-Depth Information
We will create two JSPs, shown in Listing 2-21 and Listing 2-22, to illustrate the use of the
<jsp:include> action.
Listing 2-21. main.jsp
1.<html>
2.<head>
3.</head>
4.<body>
5.<%out.print("Inside main.jsp"); %><br/>
6.<jsp:include page="sub.jsp"/>
7.</body>
8.</html>
Line 6 : Uses the <jsp:include> to include the target JSP page ( sub.jsp )
Listing 2-22. sub.jsp
1.<html>
2.<head>
3.</head>
4.<body>
5.<%out.print("Inside sub.jsp"); %><br/>
6.</body>
7.</html>
Figure 2-28 shows the output when main.jsp is accessed.
Figure 2-28. Using the <jsp:include> action
The <jsp:forward> Action
The <jsp:forward> 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:
<jsp:forward page="relativeURL" />
We will use the two JSPs created in the previous section to illustrate the use of the <jsp:forward>
action as illustrated in the Listing 2-23 and 2-24.
 
Search WWH ::




Custom Search