jsp页面中jstl标签详解

 

 

1、加载jsp页面的标签

    1.导入jar包。html

    2.配置,步骤以下:java

            2.1 在 web.xml 文件中添加如下配置:注意文件的后缀是tld格式,通常会在WEB—INF下面的tld文件夹下面。web

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" 
    xmlns="http://java.sun.com/xml/ns/j2ee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
        http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
	<jsp-config>
	<taglib>
	<taglib-uri>http://java.sun.com/jstl/fmt</taglib-uri>
	<taglib-location>/WEB-INF/fmt.tld</taglib-location>
	</taglib>
	<taglib>
	<taglib-uri>http://java.sun.com/jstl/fmt-rt</taglib-uri>
	<taglib-location>/WEB-INF/fmt-rt.tld</taglib-location>
	</taglib>
	<taglib>
	<taglib-uri>http://java.sun.com/jstl/core</taglib-uri>
	<taglib-location>/WEB-INF/c.tld</taglib-location>
	</taglib>
	<taglib>
	<taglib-uri>http://java.sun.com/jstl/core-rt</taglib-uri>
	<taglib-location>/WEB-INF/c-rt.tld</taglib-location>
	</taglib>
	<taglib>
	<taglib-uri>http://java.sun.com/jstl/sql</taglib-uri>
	<taglib-location>/WEB-INF/sql.tld</taglib-location>
	</taglib>
	<taglib>
	<taglib-uri>http://java.sun.com/jstl/sql-rt</taglib-uri>
	<taglib-location>/WEB-INF/sql-rt.tld</taglib-location>
	</taglib>
	<taglib>
	<taglib-uri>http://java.sun.com/jstl/x</taglib-uri>
	<taglib-location>/WEB-INF/x.tld</taglib-location>
	</taglib>
	<taglib>
	<taglib-uri>http://java.sun.com/jstl/x-rt</taglib-uri>
	<taglib-location>/WEB-INF/x-rt.tld</taglib-location>
	</taglib>
	</jsp-config>
</web-app>

2、核心库

        根据上面的配置好后,那就须要在jsp页面导入jstl标签库,主要用来保存、删除数据、遍历数据。好比:sql

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

上面第二个是导入格式标签库,主要用来格式化并输出文本、日期、时间、数字。api

下面是导入函数标签库,主要是用来处理通用的字符串处理函数的。app

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

主要标签库,以下:jsp

标签 描述
<c:out> 用于在JSP中显示数据,就像<%= ... >
<c:set> 用于保存数据
<c:remove> 用于删除数据
<c:catch> 用来处理产生错误的异常情况,而且将错误信息储存起来
<c:if> 与咱们在通常程序中用的if同样
<c:choose> 自己只当作<c:when>和<c:otherwise>的父标签
<c:when> <c:choose>的子标签,用来判断条件是否成立
<c:otherwise> <c:choose>的子标签,接在<c:when>标签后,当<c:when>标签判断为false时被执行
<c:import> 检索一个绝对或相对 URL,而后将其内容暴露给页面
<c:forEach> 基础迭代标签,接受多种集合类型
<c:forTokens> 根据指定的分隔符来分隔内容并迭代输出
<c:param> 用来给包含或重定向的页面传递参数
<c:redirect> 重定向至一个新的URL.
<c:url> 使用可选的查询参数来创造一个URL

    标签详细介绍,请看这篇文章:http://blog.csdn.net/u013074999/article/details/52810612函数

     特别叙说一下函数的自定义:url

         好比在jsp页面头部,先引入:spa

<c:set var="rootTreeNode"  value="${indexApi:findRootTreeNode()}"></c:set>

        那么这句话-->indexApi:findRootTreeNode() 怎么查找呢?

         找到项目目录,tld文件夹相对应的tid文件。

         在文件里面就有这样的定义:

<function>
	    		<name>findRootTreeNode</name>
	    		 <function-class>com.test.api.TopApi</function-class>
		        <function-signature>
		            com.test.mode.TreeNode findRootTreeNode()
		        </function-signature>
	    </function>

          同时com.test.api.TopApi类中须要有findRootTreeNode()这个方法,而后具体的代码根据本身的需求进行定义。

相关文章
相关标签/搜索