JSTL下载地址:http://download.csdn.net/source/3442194
配置说明如下:
1.首先将解压的文件进行解压,其中lib、tld是我们项目中要用到的。
2.将lib中的jar导入项目中。
3.在WEB-INF同级目录下新建tlds文件夹,并将tld中所有文件拷贝到其中。
4.配置web.xml:
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<jsp-config>
<taglib>
<taglib-uri>http://java.sun.com/jsp/jstl/core</taglib-uri>
<taglib-location>/tlds/c.tld</taglib-location>
</taglib>
</jsp-config>
</web-app>
jsp-config标签只需放在web-app的根元素下即可。
taglib-uri的值决定了在JSP中引用标签库时所指定的URL。
5.实例使用
<%--
Document : newjsp
Created on : 2011-7-14
Author : Mr.Jin
--%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
一般用途的标签:c:out, c:set, c:remove, c:catch
<c:set var="varaible" value="myTest"/>
<c:out default="hello world" value="test"/>
${varaible}
<c:remove var="varaible"/>
<c:out default="novar" value="${varaible}"/>
//----------------------------------------------------------------------
条件标签:c:if, c:choose, c:when, c:otherwise
<c:if test="${5<7}" var="result">
body content
</c:if>
<c:out value="${result}"/>表达式计算结果
<!--用于条件选择,它和c:when以及c:otherwise一起使用-->
<!--c:when代表c:choose的一个分支-->
<!--c:otherwise,必须以c:choose作为它的父标签,必须是c:choose的最后分支-->
<c:choose>
<c:when test="3>4">3确实大于4</c:when>
<c:when test="4>5">4确实大于5</c:when>
<c:otherwise>
以上条件均不正确,这otherwise相当于default。
</c:otherwise>
</c:choose>
//----------------------------------------------------------------------
迭代标签:c:forEach,c:forTokens
c:forEach,在一个包含一等系列对象的Collection中迭代计算它的bodyContent,或者重复迭代固定的次数
按固定次数迭代
<c:forEach begin="0" end="4" step="1">
<br/>for each item
</c:forEach>
按集合迭代
<c:forEach var="varName" items="collection">
${varName}
</c:forEach>
//----------------------------------------------------------------------
URL相关的标签c:import,c:redirect,c:url,c:param
</body>
</html>