zoukankan      html  css  js  c++  java
  • JSP指令你知多少?

     JSP的指令有3种:

    1.page指令:用来描述JSP文件的全局属性,如页面的编码规则。

    2.Include指令:用于JSP页面中包含另外一个文件。

    3.Taglib指令:用于让用户自定义标签。

     

     

    一.Page指令 用来定义JSP的全局属性。

     常用属性:

    1.language属性 

    2.Extends属性  继承父类,并使用父类变量

    3.Import属性

    4.contentType属性

    5.pageEncoding属性

     

    二.Include指令:通过代码的重用,达到减少工作量的目的。Include指令有两种形式:

    1.<%@ include file=” ”>

    2.<jsp:include flush=”true” page=” ”></jsp:include>

     

    前者是指令元素(静态包含),     后者是行为元素(动态包含)

    included.jsp文件如下:

    <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
    <head>
    <title>include指令使用实例</title>
    </head> 
      <body>
        <table border="1" width="60%">
           <tr>
               <th>&nbsp;表头1</th>
               <th>&nbsp;表头2</th>
               <th>&nbsp;表头3</th>
           </tr>
           <tr>
               <th> &nbsp;</th>
               <th> &nbsp;</th>
               <th> &nbsp;</th>
           </tr>
        </table>
      </body>
    </html>

    上图为included.jsp的页面,将这个页面用include指令插入到index.jsp

    Index.jsp代码如下:

    <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
    <html>  
      <body>
        <center>这是include指令的静态包含,也叫指令元素. </center><br><hr>
        <p>
        <center><%@ include file="MyJsp.jsp" %></center>
        <hr>
        </p>
         <center>注意:格式为使用include时不要忘了前面的@</center>
      </body>
    </html>

    三.Taglib指令  用来指定标签库以及自定义标签库的前缀

    语法:<%@ taglib uri=”URIToTagLibrary” prefix=”tagPrefix” %>

    其中,uri是标签库的路径;prefix是标签的前缀。

    如下:

    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c">

    <c:forEach>

       <c:if test=""></c:if>

    </c:forEach>

  • 相关阅读:
    mysql 备份脚本
    (四)监控cpu
    (三)修改图形乱码问题
    (二)centos7安装zabbix agentd端
    (一)Centos7安装zabbix3.4 server端
    (五)条件测试
    (四)mysql数据类型
    (三)mysql数据库基本操作
    (二)mysql忘记root密码
    (五)cobbler自定义系统安装
  • 原文地址:https://www.cnblogs.com/xrong/p/2977936.html
Copyright © 2011-2022 走看看