在Tomcat中安装JSTL

[入库:2005年8月18日] [更新:2007年3月25日]

本文简介:选择自 sdlcn 的 blog

前提 os: win2000
     tomcat已经配置好(tomcat可以到http://jakarta.apache.org/tomcat 下载)
开始实战啦
1.准备jstl
   到http://apache.towardex.com/jakarta/taglibs/standard/下载jakarta-taglibs-standard-current.zip
解压后成为jakarta-taglibs-standard-1.1.1

2.准备web开发目录
   比如我的web目录为h:\webapp\myweb\(当然可以把你的web应用放在%tomcat_home%\webapps\),称为工作目录working folder,在工作目录h:\webapp\myweb\下建立web-inf\lib,web-inf\classes

3.拷贝.jar文件
   将jakarta-taglibs-standard-1.1.1\lib\下的两个jar文件:standard.jar和jstl.jar文件拷贝到\web-inf\lib\下

4.拷贝.tld文件
 将jakarta-taglibs-standard-1.1.1\tld\下的8个tld类型文件拷到"working folder\web-inf\"下

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/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>

</web-app>
6.建立一个名为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>测试你的第一个使用到jstl 的网页</title>
</head>
<body>
<c:out value="欢迎测试你的第一个使用到jstl 的网页"/>
</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.开启tomcat,进行调试,我的输出结果是

欢迎测试你的第一个使用到jstl 的网页
你使用的浏览器是:
mozilla/4.0 (compatible; msie 6.0; windows nt 5.0) david o'davies


注:如果你的tld文件个数为15个,在上面的web.xml中<taglib-location>中更改。如果想要请和我联系
cnsdl@126.com

本文关键:在Tomcat中安装JSTL
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top