本章目标
了解JSTL的主要作用;
在项目中安装并配置JSTL。

 

JSTL简介

JSTL(JSP Standard Tag Library,JSP标准标签库)是一个开放源代码的标签组件,由Apache的Jakarta小组开发,可以直接从http://tomcat.apache.org/taglibs/下载

JSTL简介及安装_sql

 

JSTL主要的标签分类

JSTL简介及安装_开发工具_02

 

安装JSTL 1.2

下载来的JSTL.是以jar包的形式存在的,直接将此Jar包保存在WEB-INF/lib目录之中,之后可以直接通过WINRAR工具打开此JAR包,并且将里面的META-INF文件夹中的几个主要标签配置文件:c.tld、fmt.tld、fn.tld、sql.tld、x.tld保存在WEB-INF文件夹之中

JSTL简介及安装_java_03


 

简单的JSTL程序

<%@ page language="java" contentType="text/html" pageEncoding="utf-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
<title>第1个JSTL程序</title>
</head>
<body>
	<h3><c:out value="Hello World!!!"></c:out></h3>
</body>
</html>

效果图:

JSTL简介及安装_web.xml_04

 

我的是MyEclipse 10软件,不需要自己手工配置,就可以直接使用。

 

配置web.xml

<jsp-config>
  <taglib>
  <taglib-uri>http://www.baidu.cn/jstl/core</taglib-uri>
  <taglib-location>/WEB-INF/c.tld</taglib-location>
  </taglib>
  <taglib>
  <taglib-uri>http://www.baidu.cn/jstl/fmt</taglib-uri>
  <taglib-location>/WEB-INF/fmt.tld</taglib-location>
  </taglib>
  <taglib>
  <taglib-uri>http://www.baidu.cn/jstl/fn</taglib-uri>
  <taglib-location>/WEB-INF/fn.tld</taglib-location>
  </taglib>
  <taglib>
  <taglib-uri>http://www.baidu.cn/jstl/sql</taglib-uri>
  <taglib-location>/WEB-INF/sql.tld</taglib-location>
  </taglib>
  <taglib>
  <taglib-uri>http://www.baidu.cn/jstl/x</taglib-uri>
  <taglib-location>/WEB-INF/x.tld</taglib-location>
  </taglib>
</jsp-config>

 

小结
JSTL是一个第三方的开源标签库;
JSTL操作时需要自己手工配置,如果通过MyEclipse开发,则可以直接使用。