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>

  • 相关阅读:
    微信小程序分享及信息追踪
    vue刷新路由,不刷新页面
    vue中是使用富文本编辑器vue-quill-edit
    下载配置nodeJs,cnpm,webpack,vue-cli等,刚装的系统,所有东西重新配置
    promise学习总结
    【转】前端的BFC、IFC、GFC和FFC
    ES6中export与export default的区别
    前端常见跨域解决方案
    vue2.0s中eventBus实现兄弟组件通信
    RHEL5 yum更新源
  • 原文地址:https://www.cnblogs.com/xrong/p/2977936.html
Copyright © 2011-2022 走看看