The Document Structure in Practice

I l @ ve RuBoard

To make this work, you'll create several subdirectories under the JSP parent directory. The overall structure will follow this form:

 JSP ->    index.jsp    cust ->      Login.jsp    images ->      bfglogo.jpg      products ->        34545656large.jpg        34545656small.jpg    includes ->       bfgheader.jsp       bfgfooter.jsp 

To organize the file layout better, you'll create a number of directories to hold specific groups of pages (pages related to account maintenance under cust, product display pages under product, and so on). All the images will live under their own directory, with product images in a subdirectory by themselves . Finally, you will use a directory called include to hold the header and footer information.

When the organization has begun to take shape, you can move the pieces of the wireframe that you copied into the header, move the content and footer into the various appropriate subdirectories, and move the images where needed. When you do an ant dist and load up the Web page from Tomcat, you will see that it actually gets the same content that you've been looking at all along. Amazing!

One tweak that you will have to make is in the include directives. Here are what the modified include directives look like in the finished site:

 <%@ include file="/jsp/includes/bfgheader.jsp" %> <%@ include file="/jsp/includes/bfgfooter.jsp" %> 

This might seem more than a little counterintuitive, especially because the image tag looks like this:

 <img border="0" src="/bfg/jsp/images/products/0672320959.jpg" align="left" width="140" graphics/ccc.gif height="173"> 

Why does the image tag's absolute path start at /bfg while the include tag starts at /jsp ? It's because the image request is a normal HTTP transfer and is relative to the root of the Web server, whereas the include is relative to the application's root. This means that Tomcat is looking in the bfg directory already. By the way, this took a bit of research ”and many JSP errors ”to find out.

You should add one more thing to the header ”a secondary include to the auto-login code that you wrote in Chapter 8, "Retrieving, Storing, and Verifying User Input." This will ensure that, no matter what page a user starts a session with, the site will try to extract the cookie and log in that user .

Listings 9.4 and 9.5 show the finished header and footer.

Listing 9.4 bfgheader.jsp
 <%@ page import="com.bfg.product.Category" %> <%@ page import="java.util.Set" %> <%@ page import="java.util.Iterator" %> <body> <table border="0" cellpadding="0" cellspacing="0" width="100%">   <tr>     <td width="22%">     <img border="0" src="/bfg/jsp/images/bfglogo.jpg" width="175" height="168"></td>     <td width="78%">     <h1 align="center"><font color="#0000FF">Welcome to Books For Geeks!</font></h1>     </td>   </tr>   <tr>     <td width="22%">     <table border="0" cellpadding="0" cellspacing="0" width="100%">       <tr>         <td width="50%" height="35"><font size="1">         <font color="#008000">In your         cart:<br>         5 Items totaling .43</font>         <a href="http://www.boston.com/sports/redsox">[check out]</a></font></td>       </tr>     </table>     <p>Departments</p>     <blockquote>       <h5><a href="index.htm">Java</a><br>       <a href="index.htm">C++</a><br>       <a href="index.htm">Databases</a><br>       <a href="index.htm">Programming</a><br>       <a href="index.htm">Windows</a><br>       <a href="index.htm">Unix</a></h5>     </blockquote>     <p><a href="index.htm">View Basket</a><br>     <a href="index.htm">Check Out</a><br>     <a href="index.htm">My Account</a></p>     <p>&nbsp;</p>     <p>&nbsp;</p>     <p>&nbsp;</td>     <td width="78%" valign="top"> 
Listing 9.5 bfgfooter.jsp
 </td>   </tr> </table> </body> 
I l @ ve RuBoard


MySQL and JSP Web Applications. Data-Driven Programming Using Tomcat and MySQL
MySQL and JSP Web Applications: Data-Driven Programming Using Tomcat and MySQL
ISBN: 0672323095
EAN: 2147483647
Year: 2002
Pages: 203
Authors: James Turner

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net