web13-jstl

web jstl

概述

  • jsp standard tag library,SUN公司制定的一套 jsp 标准标签库

  • jstl共有5个不同功能的标签库组成

    标签库功能描述 标签库的URI 建议前缀
    核心标签库Core http://java.sun.com/jsp/jstl/core c
    XML标签库 http://java.sun.com/jsp/jstl/xml x
    国际化/格式化标签库I18N http://java.sun.com/jsp/jstl/fmt fmt
    数据库标签库SQL http://java.sun.com/jsp/jstl/sql sql
    EL自定义函数 http://java.sun.com/jsp/jstl/functions fn

使用

  • 安装
    • 下载jstl的安装包:http://tomcat.apache.org/taglibs/standard/
    • 解压下载的安装包,然后将里面的两个jar包build到项目中
      • jstl.jar包含了jstl规范中的接口和相关的类
      • standard.jar包含了实现jstl的.class文件和5个标签库描述符文件
  • 引入
    • 使用jsp的taglib指令引入需要的标签库
      <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
      
  • 使用
    • c:out
      <%-- 向页面输出Hello World --%>
      <c:out value="Hello Word"></c:out>
      
    • c:if
      <%-- 条件判断 --%>
      <c:if test="${ age==1 }">
      	<font color="red">helloword</font>
      </c:if>
      
    • c:forEach
      <% 
      	String[] arr = {"apple", "orange", "banana"};
      %>
      <c:forEach var="i" items="<%= arr %>">		
      	${ i }
      </c:forEach>
      
    • c:set
      <c:set value="1" var="age"></c:set>
      
发布了26 篇原创文章 · 获赞 1 · 访问量 591

猜你喜欢

转载自blog.csdn.net/laonxs/article/details/104366683
今日推荐