Accessibility
 
Home > Products > UltraDev > Support > Building Common Applications
Dreamweaver UltraDev Icon Macromedia Dreamweaver UltraDev Support Center - Building Common Applications
Understanding how the <jsp:include> tag works

The <jsp:include> action tag has the following basic syntax:

<jsp:include page="local_URL " flush="true"/>

The page attribute defines the file containing your JSP logic. The flush attribute tells the server to send the current page's output buffer (the part of the page that's already been processed) to the browser before processing the included file. According to version 1.1 of the JSP specification, the flush attribute must be set to true.

Note: Because the output buffer must be flushed before processing a <jsp:include> tag, you cannot use certain behaviors after the tag. These behaviors include forwarding to another page, setting cookies, or setting other HTTP headers.

You can use the <jsp:include> tag to replace blocks of JSP code in your HTML. For example, suppose you have a page called mathprobs.jsp that contains the following mix of HTML and JSP code:

<p>What is the sum of 4 and 13?</p>
<font color="blue">
<% 
int num1 = 4;
int num2 = 13;
int sum = num1 + num2; 
out.print("<p>The sum is " + sum + ".</p>"); 
%>
</font>

You can separate logic from presentation in the mathprobs.jsp page by replacing the JSP code block with a <jsp:include> tag as follows:

<p>What is the sum of 4 and 13?</p> 
<font color="blue">
<jsp:include page="answer.jsp" flush="true"/>
</font>

Next, you create a blank file called answer.jsp and enter the JSP code block, as follows:

<% 
int num1 = 4;
int num2 = 13;
int sum = num1 + num2; 
out.print("<p>The sum is " + sum + ".</p>"); 
%>

When the server processes the mathprobs.jsp page and encounters your <jsp:include> tag, it runs the answer.jsp page specified in the tag, replaces the tag with the output (here, with the output string "<p>The sum is 17.</p>"), and resumes processing the rest of the mathprobs.jsp page.

To Table of Contents Back to Previous document Forward to next document