Home | | Internet & World Wide Web HOW TO PROGRAM | | Internet Programming | | Web Programming | jsp:include Action - JavaServer Pages (JSP) Standard Actions

Chapter: Internet & World Wide Web HOW TO PROGRAM - JavaServer Pages (JSP): Bonus for Java™ Developers

| Study Material, Lecturing Notes, Assignment, Reference, Wiki description explanation, brief detail |

jsp:include Action - JavaServer Pages (JSP) Standard Actions

We continue our JSP discussion with the JSP standard actions (Fig. 31.5).

Standard Actions

 

We continue our JSP discussion with the JSP standard actions (Fig. 31.5). These actions provide JSP implementors with access to several of the most common tasks performed in a JSP, such as including content from other resources, forwarding requests to other resourc-es and interacting with JavaBeans. JSP containers process actions at request time. Actions are delimited by <jsp:action> and </jsp:action>, where action is the standard action name. In cases where nothing appears between the starting and ending tags, the XML emp-ty element syntax <jsp:action /> can be used. Figure 31.5 summarizes the JSP standard actions. We use the actions in the next several subsections.



 

1. <jsp:include> Action

 

JavaServer Pages support two include mechanisms—the <jsp:include> action and the include directive. Action <jsp:include> enables dynamic content to be included in a JavaServer Page. If the included resource changes between requests, the next request to the JSP containing the <jsp:include> action includes the new content of the resource. On the other hand, the include directive copies the content into the JSP once, at JSP translation time. If the included resource changes, the new content will not be reflected in the JSP that used the include directive unless that JSP is recompiled. Figure 31.6 de-scribes the attributes of action <jsp:include>.

 


 

The next example demonstrates action <jsp:include> using four XHTML and JSP resources that represent both static and dynamic content. JavaServer Page include.jsp (Fig. 31.10) includes three other resources: banner.html (Fig. 31.7), toc.html (Fig. 31.8) and clock2.jsp (Fig. 31.9). JavaServer Page include.jsp creates an XHTML document containing a table in which banner.html spans two columns across the top of the table, toc.html is the left column of the second row and clock2.jsp (a simplified version of Fig. 31.1) is the right column of the second row. Figure 31.10 uses three <jsp:include> actions (lines 38–39, 48 and 55–56) as the content in td elements of the table. Using two XHTML documents and a JSP in Fig. 31.10 demonstrates that JSPs can include both static and dynamic content. The output windows in Fig. 31.10 demonstrate the results of two separate requests to include.jsp.

To test Fig. 31.10 in Tomcat, copy banner.html, toc.html, clock2.jsp, include.jsp and the images directory into the jsp directory created in Section 31.3. Open your Web browser and enter the following URL to test welcome.jsp:

http://localhost:8080/advjhtp1/jsp/include.jsp

 

 

    <!-- Fig. 10.7: banner.html        -->

 

      <!-- banner to include in another document -->

      <div style = "width: 580px">

      <p>

      Java(TM), C, C++, Visual Basic(R),

      Object Technology, and <br /> Internet and

      World Wide Web Programming Training&nbsp;<br />

      On-Site Seminars Delivered Worldwide

      </p>

 

        <p>

<a href = "mailto:deitel@deitel.com">

deitel@deitel.com</a><br />

        978.579.9911<br />

        490B Boston Post Road, Suite 200,

        Sudbury, MA 01776

        </p>

</div>

     <!-- Fig. 10.8: toc.html     --> 

     <!-- contents to include in another document -->    

    <p><a href = "http://www.deitel.com/books/index.html">

    Publications/BookStore

    </a></p>

 

    <p><a href = "http://www.deitel.com/whatsnew.html">

    What's New

      </a></p>

 

      <p><a href = "http://www.deitel.com/books/downloads.html">

      Downloads/Resources

      </a></p>

 

      <p><a href = "http://www.deitel.com/faq/index.html">

      FAQ (Frequently Asked Questions)

      </a></p>

 

      <p><a href = "http://www.deitel.com/intro.html">

      Who we are

      </a></p>

      <p><a href = "http://www.deitel.com/index.html">

      Home Page

      </a></p>

      <p>Send questions or comments about this site to

      <a href = "mailto:deitel@deitel.com">

      deitel@deitel.com

      </a><br />

      Copyright 1995-2002 by Deitel &amp; Associates, Inc.

      All Rights Reserved.

</p>

Fig. 31.8 Table of contents (toc.html) to include down the left side of the XHTML document created by Fig. 31.10

 

 

 

 

<!-- Fig. 10.9: clock2.jsp   -->

<!-- date and time to include in another document -->

    

<table>  

<tr>

<td style = "background-color: black;">   

<p class = "big" style = "color: cyan; font-size: 3em;

font-weight: bold;">   

    

<%= new java.util.Date() %> 

</p>

      </td>

      </tr>

</table>

 

Fig. 31.9 JSP clock2.jsp to include as the main content in the XHTML document created by Fig. 31.10

 

 

 

    <?xml version = "1.0"?>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<!-- Fig. 10.7: include.jsp -->

 

    <html xmlns = "http://www.w3.org/1999/xhtml">

 

 

    <head>

<title>Using jsp:include</title>

<style type = "text/css">

body {

font-family: tahoma, helvetica, arial, sans-serif;

}

 

table, tr, td {

font-size: .9em;

border: 3px groove;

padding: 5px;

background-color: #dddddd;

     </style>

     </head>

 

     <body>

     <table>

<tr>

<td style = "width: 160px; text-align: center">

<img src = "images/logotiny.png"

width = "140" height = "93"

alt = "Deitel & Associates, Inc. Logo" />

</td>

 

<td>

 

<%-- include banner.html in this JSP --%>

<jsp:include page = "banner.html"

flush = "true" />

 

</td>

</tr>

<tr>

<td style = "width: 160px"> 

    

<%-- include toc.html in this JSP --%>

<jsp:include page = "toc.html" flush = "true" />

    

</td>    

    

<td style = "vertical-align: top">   

    

<%-- include clock2.jsp in this JSP --%>  

<jsp:include page = "clock2.jsp" 

flush = "true" /> 

    

</td>    

 

     </tr>

     </table>

     </body>

     </html>


Fig. 31.10     JSP include.jsp Includes resources with <jsp:include>

 


Study Material, Lecturing Notes, Assignment, Reference, Wiki description explanation, brief detail


Copyright © 2018-2020 BrainKart.com; All Rights Reserved. Developed by Therithal info, Chennai.