安裝JSTL1.2 日期:2017-06-27
-
下載jstl1.2版本,下載地址:http://repo2.maven.org/maven2/javax/servlet/jstl/
- 用壓縮包打開jstl1.2,一般開發只需要里面的五個*.tid文件,c.tld,fmt.tld ,fn.tld,sql.tld,x.tld 就OK了,如下圖示:
- 把以上五個文件復制到項目工程的WEB-INF文件夾中,我的文件路徑是:D:\A01\web.project\WebContent\WEB-INF
- 將jstl.jar復制到項目工程的WEB-INF文件夾的lib文件中
- 配置WEN-INF文件夾中的web.xml,如下代碼:
<jsp-config> <taglib> <taglib-uri>http://www.mldn.cn/jst/core</taglib-uri> <taglib-location>/WEB-INF/c.tld</taglib-location> </taglib> <taglib> <taglib-uri>http://www.mldn.cn/jst/fmt</taglib-uri> <taglib-location>/WEB-INF/fmt.tld</taglib-location> </taglib> <taglib> <taglib-uri>http://www.mldn.cn/jst/fn</taglib-uri> <taglib-location>/WEB-INF/fn.tld</taglib-location> </taglib> <taglib> <taglib-uri>http://www.mldn.cn/jst/sql</taglib-uri> <taglib-location>/WEB-INF/sql.tld</taglib-location> </taglib> <taglib> <taglib-uri>http://www.mldn.cn/jst/x</taglib-uri> <taglib-location>/WEB-INF/x.tld</taglib-location> </taglib> </jsp-config>
可以不配置web.xml文件,直接使用他的路徑也可以,但是一般開發過程中習慣配置web.xml文件
- 沒配置web.xml文件的測試代碼:
<%@ page language="java" contentType="text/html" pageEncoding="GBK"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <%@ taglib uri="/WEB-INF/c.tld" prefix="c" %> <html> <head> <meta http-equiv="Content-Type" content="text/html"> <title>Insert title here</title> </head> <body> <h2> <c:out value="Hello Word!!"></c:out> </h2> </body> </html>
注意:uri="/WEB-INF/c.tld"是標簽庫的路徑
- 配置web.xml文件的測試代碼:
<%@ page language="java" contentType="text/html" pageEncoding="GBK"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <%@ taglib uri="http://www.mldn.cn/jst/core" prefix="c" %> <html> <head> <meta http-equiv="Content-Type" content="text/html"> <title>Insert title here</title> </head> <body> <h2> <c:out value="Hello Word!!"></c:out> </h2> </body> </html>
注意:配置后可以直接使用配置的虛擬路徑
uri="http://www.mldn.cn/jst/core"可以查看步驟5的代碼,這樣做的好處是:當我們修改或改動實際路徑是,不用修改代碼的路徑,這樣方便可用。