Article

The JSP Files - Parts 1 to 8: Tagged and Bagged

Page: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 Next

Alphabet Soup For The Soul

If you've used C before, you're probably already familiar with the "include" directive that appears near the beginning of every C program. JSP supports an equivalent include() function, which does much the same thing. Take a look at this simple example:

<html>      
<head>      
<title> Thought For The Day</title>      
</head>      
<body>      
     
Thought For The Day:      
<br>      
<%@ include file="thought.html" %>      
     
</body>      
</html>

[thought.html]

Ever wonder if illiterate people get the full effect of alphabet soup?

In this case, JSP will automatically read the contents of the file "thoughts.html", and display a composite page which looks like this:

<html>      
<head>      
<title>Thought For The Day</title>      
</head>      
<body>      
     
Thought For The Day:      
<br>      
Ever wonder if illiterate people get the full effect of alphabet soup?      
     
</body>      
</html>

A very useful and practical application of the include() function is to use it to include a standard footer or copyright notice across all the pages of a Web site, like this:

<html>      
<head>      
</head>      
     
<body>      
     
...your HTML page...      
     
<br>      
     
<%@ include file="footer.html" %>      
     
</body>      
</html>

where "footer.html" contains:

<font size=-1 face=Arial>This material copyright Melonfire, 2001.      
All rights reserved.</font>

Now, this footer will appear on each and every page that contains the include() statement above - and, if you need to change the message, you only need to edit the single file named "footer.html"!

And that's about it for this week. We've shown you the basic building blocks of JSP, and next time, we'll be using those fundamental concepts to demonstrate JSP's control structures. Don't miss it!

Note: All examples in this article have been tested on Linux/i586 with Tomcat 3.2 and JServ 1.1. Examples are illustrative only, and are not meant for a production environment. YMMV!
Copyright Melonfire, 2000. All rights reserved.

If you liked this article, share the love:
Print-Friendly Version Suggest an Article

Sponsored Links