Accessibility
 
Home > Products > UltraDev > Support > Building Common Applications
Dreamweaver UltraDev Icon Macromedia Dreamweaver UltraDev Support Center - Building Common Applications
Choosing a solution

JSP offers four basic ways to separate logic from presentation. You can use a JSP include directive, write a JavaBean, create a JSP custom tag, or use the <jsp:include> tag.

A JSP include directive is similar to an HTML server-side include. When you run a page with the directive, the server replaces the directive with the contents of the specified file. Here's the directive's syntax:

<%@ include file = "local_URL " %> 

The main drawback with the include directive is that changes you make to the include file are not automatically recognized by the JSP application server. The server normally recompiles any updated JSP page. However, as far as the server is concerned in this case, the page calling the modified include file hasn't changed (its date stamp is still the same), so the server doesn't recompile it. A less-than-elegant solution is to manually save the calling page every time you make a change to the include file, thus forcing the server to recompile it.

A second way to separate logic from presentation is to write a JavaBean that generates the date list. However, JavaBeans are meant to be stand-alone software components not bound to any single application or use. They're not meant to generate application-specific content like the Arrow date list. Using a JavaBean in this situation may be inappropriate.

A third way to separate logic from presentation is to create a custom tag that generates the date list. Unlike JavaBeans, JSP custom tags are designed to generate dynamic HTML content (among other things). However, creating a custom tag is an non-trivial matter and makes sense only if you want to reuse the tag in other pages or in other applications. In this case, you don't.

A fourth way to separate logic from presentation is to use the <jsp:include> action tag. Not to be confused with the include directive, which inserts the full text of a file in the calling page, the <jsp:include> tag inserts the "output" of the file into the calling page. For example, suppose the include file consists of the following JSP/Java code:

<%
int num1 = 12, num2 = 9;
int sum = num1 + num2;
out.print(sum);
%>

An include directive would insert the above code without modification into the calling page. In contrast, a <jsp:include> tag would first execute the code then insert the number 21 in the calling page. It's useful to think of the <jsp:include> action tag as a quick and easy custom tag.

The main advantage of the <jsp:include> tag over the include directive is that changes to a JSP include file are automatically recognized by the JSP application server. For example, the server compiles and runs the include file the first time the <jsp:include> tag calls it. If you later change the include file, the server recompiles it the next time the <jsp:include> tag calls it.

For the Arrow Aircraft welcome page, you decide to use the <jsp:include> tag to separate the date list's logic from the rest of the page.

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