JSTL环境的建立  2009-04-15   Java  

JSP标准标记库(JSP Standard Tag Library,JSTL)是一个Web应用程序中常用的定制标签库,
功能包括迭代循环、条件判断、数据输出格式化、XML操作以及数据库访问。
JSTL支持表达式语言(Expression Language,EL),从而可以指定动态属性值。
JSTL的用法相关的文档非常多,大家可以很容易搜索到,本文不再赘述,重点说明JSTL对开发运行环境的要求,
如果你根据JSTL的文档无法得到应有的结果,
特别是使用functions抛出EL functions are not supported.异常时,请关注本文。

JSTL分为两大版本,1.0系列和1.1系列。其中1.1系列增加了一个字符串函数的功能。大家需要注意。
如果要使用JSTl,需要如下三个步骤,缺少任何一步就有可能导致JSTL失效。

1.引入jar文件
各种版本:JSTL各种版本
下载最新版JSTL1.2:JSTL1.2,将其引入进来。

        
2.jsp中加入声明语句
1.1版本(需要JSP 2.0容器,Tomcat5.0以上版本支持):

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/xml" prefix="x" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %>

1.0版本(需要JSP 1.2容器,注意:没有functions标签库):

<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="http://java.sun.com/jstl/xml" prefix="x" %>
<%@ taglib uri="http://java.sun.com/jstl/sql" prefix="sql" %>

3.修改web.xml
2.5版本,支持JSTL1.1以上版本:

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns="http://java.sun.com/xml/ns/javaee"
	xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
              http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
	id="WebApp_ID" version="2.5">
......
</web-app>

2.4版本,支持JSTL1.1以上版本:

<web-app id="WebApp_ID" version="2.4"
	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">
......
</web-app>

2.3版本,支持JSTL1.0版本。

<!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 id="WebApp_ID">
......
</web-app>

2.2版本,支持JSTL1.0版本。

<!DOCTYPE web-app PUBLIC
  "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
  "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">
<web-app id="WebApp_ID">
......
</web-app>

 发表评论

(必填)

(必填)

评论(必填,最多字数:100):