一、在Tomcat中安裝JSTL
前提 OS: WIN2003;Tomcat5.5;tomcat已經(jīng)配置好。 
1.準(zhǔn)備jstl
   到http://archive.apache.org/dist/jakarta/taglibs/standard/binaries/下載jakarta-taglibs-standard-1.1.2.zip
解壓后成為jakarta-taglibs-standard-1.1.2 
2.準(zhǔn)備web開發(fā)目錄
   比如我的web目錄系統(tǒng)默認(rèn)目錄%tomcat_home%\webapps\ROOT下,工作目錄為ROOT,也可以自定義工作目錄,但必須要保證工作目錄下建立WEB-INF\lib,WEB-INF\classes 
3.拷貝.jar文件
   將jakarta-taglibs-standard-1.1.2\lib\下的兩個(gè)jar文件:standard.jar和jstl.jar文件拷貝到工作目錄的\WEB-INF\lib\下 
4.拷貝.tld文件(可選)
 將jakarta-taglibs-standard-1.1.2\tld\下的15個(gè)tld類型文件拷到"Working folder\WEB-INF\tld"下 
5.在工作目錄下的\WEB-INF\下建立web.xml文件:(可選)
  <?xml version="1.0" encoding="ISO-8859-1"?> 
<web-app 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"
    version="2.4">
 
<taglib>
    <taglib-uri>http://java.sun.com/jstl/fmt</taglib-uri>
    <taglib-location>/WEB-INF/tld/fmt.tld</taglib-location>
</taglib> 
<taglib>
    <taglib-uri>http://java.sun.com/jstl/fmt-1_0</taglib-uri>
    <taglib-location>/WEB-INF/tld/fmt-1_0.tld</taglib-location>
</taglib>
<taglib>
    <taglib-uri>http://java.sun.com/jstl/fmt-1_0-rt</taglib-uri>
    <taglib-location>/WEB-INF/tld/fmt-1_0-rt.tld</taglib-location>
</taglib> 
<taglib>
    <taglib-uri>http://java.sun.com/jstl/core</taglib-uri>
    <taglib-location>/WEB-INF/tld/c.tld</taglib-location>
</taglib> 
<taglib>
    <taglib-uri>http://java.sun.com/jstl/core-1_0-rt</taglib-uri>
    <taglib-location>/WEB-INF/tld/c-1_0-rt.tld</taglib-location>
</taglib> 
<taglib>
    <taglib-uri>http://java.sun.com/jstl/core-1_0</taglib-uri>
    <taglib-location>/WEB-INF/tld/c-1_0.tld</taglib-location>
</taglib> 
<taglib>
    <taglib-uri>http://java.sun.com/jstl/sql</taglib-uri>
    <taglib-location>/WEB-INF/tld/sql.tld</taglib-location>
</taglib> 
<taglib>
    <taglib-uri>http://java.sun.com/jstl/sql-1_0</taglib-uri>
    <taglib-location>/WEB-INF/tld/sql-1_0.tld</taglib-location>
</taglib> 
<taglib>
    <taglib-uri>http://java.sun.com/jstl/sql-1_0-rt</taglib-uri>
    <taglib-location>/WEB-INF/tld/sql-1_0-rt.tld</taglib-location>
</taglib> 
<taglib>
    <taglib-uri>http://java.sun.com/jstl/x</taglib-uri>
    <taglib-location>/WEB-INF/tld/x.tld</taglib-location>
</taglib> 
<taglib>
    <taglib-uri>http://java.sun.com/jstl/x-1_0</taglib-uri>
    <taglib-location>/WEB-INF/tld/x-1_0.tld</taglib-location>
</taglib> 
<taglib>
    <taglib-uri>http://java.sun.com/jstl/x-1_0-rt</taglib-uri>
    <taglib-location>/WEB-INF/tld/x-1_0-rt.tld</taglib-location>
</taglib> 
<taglib>
    <taglib-uri>http://java.sun.com/jstl/fn</taglib-uri>
    <taglib-location>/WEB-INF/tld/fn.tld</taglib-location>
</taglib> 
<taglib>
    <taglib-uri>http://java.sun.com/jstl/permittedTaglibs</taglib-uri>
    <taglib-location>/WEB-INF/tld/permittedTaglibs.tld</taglib-location>
</taglib> 
<taglib>
    <taglib-uri>http://java.sun.com/jstl/scriptfree</taglib-uri>
    <taglib-location>/WEB-INF/tld/scriptfree.tld</taglib-location>
</taglib>
</web-app> 
  
提示: 
In addition to declaring the tag libraries, tutorial examples access the JSTL API and implementation. In the Application Server, the JSTL TLDs and libraries are distributed in the archive <J2EE_HOME>/lib/appserv-jstl.jar. This library is automatically loaded into the classpath of all web applications running on the Application Server, so you don't need to add it to your web application. 

  
以上摘自j2ee的tutorial,說明步驟四、五中的TLD文件注冊(cè)部分是可以省略的,WEB工程能自動(dòng)的從jar包中加載相應(yīng)的標(biāo)簽庫。 

6.建立一個(gè)名為test.jsp文件
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<%@ page contentType="text/html;charset=GB2312" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html>
<head>
<title>測(cè)試你的第一個(gè)使用到JSTL 的網(wǎng)頁</title>
</head>
<body>
<c:out value="歡迎測(cè)試你的第一個(gè)使用到JSTL 的網(wǎng)頁"/>
</br>你使用的瀏覽器是:</br>
<c:out value="${header['User-Agent']}"/>
<c:set var="a" value="David O'Davies" />
<c:out value="David O'Davies" escapeXml="true"/>
</body>
</html> 
7.顯示結(jié)果:
歡迎測(cè)試你的第一個(gè)使用到JSTL 的網(wǎng)頁
你使用的瀏覽器是:
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SailBrowser; .NET CLR 1.1.4322) David O'Davies
8.注意的問題
主要的一個(gè)問題還是路徑的問題,筆者配置了好幾次都不能成功,就是把工作目錄給弄錯(cuò)了,把項(xiàng)目的目錄誤認(rèn)為是工作目錄,一直在項(xiàng)目的目錄下配置文件,其實(shí)應(yīng)該在工作目錄下配置,當(dāng)然可以把工作目錄改成項(xiàng)目的目錄,問題也就可以解決了。
9.常出現(xiàn)的問題和提示:
org.apache.jasper.JasperException: The absolute uri: http://java.sun.com/jstl/core cannot be resolved in either web.xml or the jar files deployed with this application
出現(xiàn)這個(gè)問題主要一種可能是工作目錄的\WEB-INF\lib\下缺少standard.jar和jstl.jar文件,另外一種可能是web.xml沒有進(jìn)行TAG的正確配置。
According to TLD or attribute directive in tag file, attribute value does not accept any expressions
應(yīng)用部署運(yùn)行的時(shí)候出現(xiàn)JSP異常, 發(fā)生在使用JSTL庫的時(shí)候: According to TLD or attribute directive in tag file, attribute value does not accept any expressions, 可能是因?yàn)槭褂昧薐SP2.0版本, 同時(shí)又沒有使用JSTL core庫的備用版本(RT庫), 以下有兩種處理方法: 
a. 修改web.xml. 
<web-app 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" version="2.4">
改為2.3版本的 
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
b. 使用JSTL core RT庫 
JSTL core庫的有兩種taglib偽指令, 其中RT庫即是依賴于JSP傳統(tǒng)的請(qǐng)求時(shí)屬性值, 而不是依賴于EL來實(shí)現(xiàn)(稱為EL庫.JSP2.0將支持EL) 
JSP中使用<%@ taglib uri=http://java.sun.com/jstl/core prefix="c"%>在2.3版本都可以,在2.4就不行了, 難道是版本不兼容嗎? 
只要將 
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c"%>
改為 
<%@ taglib uri=http://java.sun.com/jstl/core_rt prefix="c"%>
就沒有問題了 
三、標(biāo)簽的使用 
C標(biāo)準(zhǔn)標(biāo)簽庫
Taglib-http://java.sun.com/jstl/core
基礎(chǔ):
1.jsp頁面引入C標(biāo)簽庫:
<@taglib uri=”http://java.sun.com/jstl/core” prefix=”c”>   //引入標(biāo)簽庫 前綴為c
2.c標(biāo)簽庫的標(biāo)簽列表
    
C標(biāo)簽庫例舉
標(biāo)簽名   用處
<c:choose>   
<c:forEach>   
<c:forTokens>   
<c:if>   
<c:import>   
<c:otherwise>   
<c:out>   把對(duì)象的數(shù)值輸出到JspWriter
<c:p