<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    posts - 23,comments - 12,trackbacks - 0

    The include Directive


    The following is the syntax for the include directive:

    <%@ include file="relativeURL" %>

    As you can see the directive accepts a single file attribute that is used to indicate the resource whose content is to be included in the declaring JSP. The file attribute is interpreted as a relative URL; if it starts with a slash it's interpreted as relative to the context of the web application (namely a context-relative path), otherwise it's interpreted as relative to the path of the JSP that contains the include directive (namely a page relative path). The included file may contain either static content, such as HTML or XML, or another JSP page.

    For example:
    <%@ include file="/copyright.html"%>


    Let's consider a real-world example of such a templating mechanism that utilizes the include directive to provide a consistent page layout for a web application.

    Consider the following two JSP pages:

    Header.jsp
        <html>
          <head><title>A Very Simple Example</title></head>
          <body style="font-family:verdana,arial;font-size:10pt;">
            <table width="100%" height="100%">
              <tr bgcolor="#99CCCC">
                <td align="right" height="15%">Welcome to this example...</td>
              </tr>
              <tr>
                <td height="75%">

    Footer.jsp
               </td>
             </tr>
             <tr bgcolor=" #99CC99">
               <td align="center" height="10%">Copyright ACompany.com 2003</td>
             </tr>
           </table>
         </body>
       </html>

    As you can see, Header.jsp declares the starting elements of an HTML table that is to be 100 percent of the size of the page and has two rows, whereas Footer.jsp simply declares the closing elements for the table. Used separately, either JSP will result in partial HTML code that will look very strange to a user but when they're combined using the include directive it's easy to create consistent pages as part of a web application.

    Let's see just how simple this basic template mechanism is to use:

    Content.jsp
        <%@ include file='./Header.jsp'%>
        <p align="center">The Content Goes Here...!!!</p>
        <%@ include file='./Footer.jsp'%>

    2、
    date.jsp
    <html>
      <body>
        <h2>Greetings!</h2>
     <P>The current time is <%=new java.util.Date()%> precisely
      </body>
    </html>

    3、
    dateBean.jsp
    <html>
        <head><title>Professional JSP, 3rd Edition</title></head>
        <body style="font-family:verdana;font-size:10pt;">
            <jsp:useBean id="date" class="com.apress.projsp20.ch01.DateFormatBean"/>
            <h2>Today's date is <%= date.getDate() %></h2>
        </body>
    </html>

    或:
    dateBean_getProperty.jsp
    <html>
        <head><title>Professional JSP, 3rd Edition</title></head>
        <body style="font-family:verdana;font-size:10pt;">
            <jsp:useBean id="date" class="com.apress.projsp20.ch01.DateFormatBean"/>
            <h2>Today's date is <jsp:getProperty name="date" property="date"/></h2>
        </body>
    </html>

    dateBean_setProperty.jsp
    <html>
        <head><title>Professional JSP, 3rd Edition</title></head>
        <body style="font-family:verdana;font-size:10pt;">
            <jsp:useBean id="date" class="com.apress.projsp20.ch01.DateFormatBean"/>
            <jsp:setProperty name="date" property="format"
                             value="EEE, d MMM yyyy HH:mm:ss z"/>
            <h2>Today's date is <jsp:getProperty name="date" property="date"/></h2>
        </body>
    </html>

    其中DateFormatBean.java:
       package com.apress.projsp20.ch01;

        import java.util.Date;
        import java.text.*;

        public class DateFormatBean {
          private DateFormat dateFormat;
          private Date date;

          public DateFormatBean() {
            dateFormat = DateFormat.getInstance();
            date = new Date();
          }

          public String getDate() {
            return dateFormat.format(date);
          }

          public void setDate(Date date) {
            this.date = date;
          }

          public void setFormat(String format) {
            this.dateFormat = new SimpleDateFormat(format);
          }
        }
    例:SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    posted on 2005-08-24 17:20 my java 閱讀(301) 評論(0)  編輯  收藏 所屬分類: jsp

    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    主站蜘蛛池模板: 免费国产叼嘿视频大全网站| 国产成人亚洲综合a∨| 热99RE久久精品这里都是精品免费| 又爽又高潮的BB视频免费看| 色九月亚洲综合网| 全亚洲最新黄色特级网站| 美女黄频免费网站| 亚洲av成人一区二区三区在线观看| 美女被暴羞羞免费视频| 亚洲av片一区二区三区| 一级毛片免费在线| 亚洲国产成人一区二区三区| 免费人成毛片动漫在线播放| 亚洲视频网站在线观看| 免费看韩国黄a片在线观看| 亚洲中文无码永久免| 四虎1515hm免费国产| 中文字幕在线视频免费| 亚洲AV无码一区二区乱子伦| 99在线精品视频观看免费| 亚洲人成人网站18禁| 中文字幕亚洲综合久久菠萝蜜| 日韩精品无码免费专区网站| 亚洲电影在线播放| 国产精品久免费的黄网站| 国产美女视频免费观看的网站| 亚洲国产综合专区在线电影 | 国产精品69白浆在线观看免费| 亚洲综合av一区二区三区不卡 | 亚洲日韩在线中文字幕第一页| 两个人看的www免费视频| 久久亚洲精品无码aⅴ大香| 成人毛片免费观看视频大全| 永久免费无码网站在线观看个 | 亚洲AV成人一区二区三区在线看| 国产成人免费高清在线观看| 免费看无码特级毛片| 四虎亚洲精品高清在线观看| 在线A亚洲老鸭窝天堂| 人妻视频一区二区三区免费| 午夜肉伦伦影院久久精品免费看国产一区二区三区 |