`
peigang
  • 浏览: 171528 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

JSTL 1.2.x guide

    博客分类:
  • JAVA
阅读更多

JSTL 1.2.x is the latest version of JSTL. There are a few differences between this version and the previous JSTL 1.1.x version. The most important difference is that JSTL 1.2.x supports Unified EL (Expression Language) , where as JSTL 1.1.x supports only traditional EL. With Unified EL it becomes very easy to combine the EL in JSF (Java Server Faces) and the EL in JSTL. This guide shows you how to install JSTL 1.2.x properly or troubleshoot your existing JSTL installation.

  • Download JSTL 1.2.x

    Get JSTL 1.2 from java.net Maven Repository for JSTL
  • Install JSTL 1.2.x

    Move the jstl-1.2.jar file to your project's WEB-INF/lib folder.
  • Configure JSTL 1.2.x

    This version of JSTL does not require any further configuration. See compatibility and depedency for more information.
  • JSTL 1.2.x Compatibility

    In short JSTL 1.2 is compatible with Unified EL, JSF 1.2, JSP 2.1, Servlet 2.5.

    JSTL 1.2.x requires a Web Server (Container) that complies with the Servlet 2.5 / JSP 2.1 (or higher) specification.

    For example: Tomcat 6.x complies with Servlet 2.5 and JSP 2.1 specifications.

    See: Tomcat Version - Servlet Spec - JSP Spec chart

    This also means that the deployment descriptor (web.xml file under your project's WEB-INF) folder must also comply with the Servlet 2.5 specification. This means that the web-app declartion and all the tags inside web.xml must be according to the Servlet 2.5 specification.

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns="http://java.sun.com/xml/ns/javaee"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
        version="2.5">
    
    </web-app>
    Having a deployment descriptor and Web Container that is Servlet Specification 2.5 and JSP Specification 2.1 compliant means that the web container supports Unified EL which is used by JSTL 1.2.

    Return to Top

  • JSTL 1.2.x Dependency

    JSTL 1.2.x comes with various tags that serve different purposes. Depending on which tags you plan to use you will need certain dependencies.

    You don't need any other dependencies if you plan to use just the core, format, function tags or just Unified EL (expression language).

    If you plan to use the sql tags then you'll need the JDBC connector JAR file for your database. You can place this connector JAR in your web container's lib folder.

    If you plan to use the xml tags then you dependent JAR files Xalan.jar, Serializer.jar.

    If you plan to use JSF along with JSTL 1.2.x then you need JSF version 1.2 which is compatible with JSP 2.1

    If I've missed any other dependencies, then you'll get an exception error message such as "ClassNotFound", "Method Not Found" etc, examine the exception, to find out which package the class or method belongs to and then search for the distributions containing those class or method files. Get the distribution version that is compatible with the JSTL version you are using.

    standard.jar is already included in jstl-1.2.jar, if you still have the standard.jar in WEB-INF/lib from and older installation of JSTL then you can remove it because it is already part of JSTL 1.2 JAR fil.e

    Dependencies for previous version (JSTL 1.1.2) is here.

    Return to Top

  • JSTL 1.2 Usage Guide

    The tag library you plan to use must be defined in each JSP page the tags appear on. If you are familiar with XML terminology this is known as name space declartion. By declaring a namespace prefix of say "c"and associating it with a taglib URI, you are basically indicating that all tags that start with c: are JSTL core tags.

    The taglib URIs are different across different versions of JSTL. Make sure that the taglib URIs you use in the JSP files match with the JSTL version you are using. The JSTL 1.2 taglib URIs are the same as JSTL 1.1.x taglib URIs.

    To see JSTL 1.1.x the taglib URIs, click on the tag library of your choice. For example see the core taglib URI.

    JSTL core:
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

    JSTL fmt:
    <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

    JSTL sql:
    <%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql" %>

    JSTL XML:
    <%@ taglib prefix="x" uri="http://java.sun.com/jsp/jstl/xml" %>

    JSTL Functions:
    <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>

Return to Top

  • JSTL 1.2 Examples

    JSTL 1.2 uses Unified EL, this means the EL in the JSTL,JSP are compatible with JSF EL.

    JSTL core tags
    <%@ page contentType="text/html;charset=UTF-8" language="java" %>
        <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
        <html>
        <head><title>JSTL 1.2 core tag example</title></head>
        <body>
            <c:set var="mysStringVariable" value="Hello World!"/>
            <c:out var="myStringVariable"/>
        </body>
        </html>


    JSTL 1.2 EL
    <%@ page contentType="text/html;charset=UTF-8" language="java" %>
        <html>
        <head><title>JSTL 1.2 EL example</title></head>
        <body>
            ${requestScope.myStringVariable}
    
            ${ 100/5 }
    
            ${ 9 <42 }
        </body>
        </html>
    
        Notice that no taglib definitions are required if only EL is written in a JSP page.


    JSTL 1.2 Function tags
    <%@ page contentType="text/html;charset=UTF-8" language="java" %>
        <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
        <html>
        <head><title>JSTL 1.2 function tags </title></head>
        <body>
            ${fn:toUpperCase(requestScope.myStringVariable)}
    
            ${ fn:escapeXml(sessionScope.siteUrl) }
    
        </body>
        </html>


    JSTL format ( fmt ) tags
    <%@ page contentType="text/html;charset=UTF-8" language="java" %>
        <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
        <html>
        <head><title>JSTL 1.2 format tag example</title></head>
        <body>
            <fmt:formatDate value="${dateVariable}" pattern="yyyy/MM/dd"/>
        </body>
        </html>


    Sometimes the format tag doesn't work as expected. Especially date formatting doesn't work. This is because the format tag requires the locale to be set. For example:
    <fmt:setLocale value="en-US"/>

    See the API doc for setting the locale to the languageCode-CountryCode of your choice.

    XML Tags Example - usage with external XML and XSTL files.
    File: mydata.xml
    <?xml version="1.0" encoding="UTF-8"?>
    <books>
        <book>
            <title>JSTL 1.2 Reference</title>
            <author>Rashmi</author>
        </book>
    </books>
    
    
    File: transform_data.xsl
    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:template match="book">
            <ul>
                <li>
                    <xsl:value-of select="title" />
                </li>
                <xsl:apply-templates select="book" />
            </ul>
        </xsl:template>
    </xsl:stylesheet>
    
    
    File: index.jsp
    <%@ page contentType="text/html;charset=UTF-8" language="java" %>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
    <%@ taglib prefix="x" uri="http://java.sun.com/jsp/jstl/xml" %>
    <html>
    <head><title>JSTL 1.2 XML Tags usage example</title></head>
    
    <body>
    
    <c:import url="mydata.xml" var="xml"/>
    <c:import url="transform_data.xsl" var="xsl"/>
    <x:transform doc="${xml}" xslt="${xsl}"/>
    
    Verify that the path (absolute, relative, context relative) of the above imported files is correct.
    Use forward slash / as a path separator.    
    </body>
    </html>


    XML Tag examples, with transformation within the JSP page (no external XSLT stylesheet).
    <%@ page contentType="text/html;charset=UTF-8" language="java" %>
        <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
        <%@ taglib prefix="x" uri="http://java.sun.com/jsp/jstl/xml" %>
        <c:import url="/data.xml" var="xmlData"/>
        <x:parse xml="${xmlData}" var="parsedDoc"   />
        <html>
            <head><title>JSTL 1.2 XML Transform Example</title></head>
            <body>
                <x:forEach select="$parsedDoc/books/book">
                    <x:out select="title"/>
                    <br/>
                    <x:out select="author"/>
                </x:forEach>
            </body>
        </html>


    SQL tags example
    <%@ page contentType="text/html;charset=UTF-8" language="java" %>
            <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
            <%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql" %>
            <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
            <!-- Define this JNDI, JDBC data source  in context.xml or ROOT.xml -->
            <sql:setDataSource dataSource="jdbc/MyDB"/>
            <sql:query var="bookTitles">
                SELECT title
                FROM book;
            </sql:query>
    
            <ul>
                <c:forEach var="title" items="${bookTitles.rows}">
                    <li>
                            <c:out value="${fn:toLowerCase(title)}" escapeXml="true"/>
                    </li>
                </c:forEach>
            </ul>
    Important Note: There are differences in configuration and JSTL URIs across different versions of JSTL. For example the taglib URIs for JSTL 1.0 is different from that of JSTL 1.1.x and 1.2, also the compatibility with the web server version, web.xml version, dependency configuration is different across versions. It is a good idea to check your version of JSTL and make sure everything is configured correctly for your version. If JSTL is configured incorrectly for its version, then these examples won't work. See configuration guides for JSTL 1.1.x and JSTL 1.2 for more details.

    Return to Top

  • Troubleshoot JSTL 1.2

    Unified EL is not evaluating

    If the Unified EL does not evaluate this is most likely a compatibility issue. If you are upgrading from a previous version of JSTL it is recommended that you start fresh on a clean slate. Verify that the Web Container and your deployment descriptor (web.xml) is compatible with Servlet Specification 2.5 or higher. See compatibility for more details.
  • 分享到:
    评论

    相关推荐

      jstl-1.2.jar免费下载

      jstl-1.2.jar下载jstl-1.2.jar下载jstl-1.2.jar下载jstl-1.2.jar下载jstl-1.2.jar下载jstl-1.2.jar下载jstl-1.2.jar下载jstl-1.2.jar下载jstl-1.2.jar下载jstl-1.2.jar下载jstl-1.2.jar下载jstl-1.2.jar下载jstl-1.2...

      jstl1.2.jar&stanard;.jar

      **JSTL 1.2**: 这是JSTL的一个版本,提供了多种标签,包括用于控制流程的 `&lt;c:if&gt;`、循环的 `&lt;c:forEach&gt;`,以及处理表达式的 `&lt;c:set&gt;`等。JSTL 1.2包含了对JSP 2.0规范的支持,并且与EL(Expression Language)很...

      jstl-1.2.jar、jstl-api-1.2.jar、jstl-impl-1.2.jar三个包

      java.lang.NoClassDefFoundError: javax/servlet/jsp/jstl/core/Config,以上错误可以使用以下策略试试,tomcat的lib文件夹下加入:jstl-1.2.jar、jstl-api-1.2.jar、jstl-impl-1.2.jar三个包。

      [jstl-1.2.jar]和[jstl-api-1.2.jar、standard.jar]两个版本.zip

      包含了两个版本jstl文件,standard.jar和jstl-api-1.2.jar是一个版本,导入时需要将两个都导入,jstl-1.2.jar是高版本的,是将低版本的两个文件合成一个了,故只需要导入一个文件即可,导入的同时在jsp文件首行写入 ...

      jstl-api-1.2.jar、jstl-impl-1.2.jar

      在给定的压缩包中,有两个关键文件:`jstl-api-1.2.jar` 和 `jstl-impl-1.2.jar`。它们分别是JSTL的API接口和实现的jar包。 **jstl-api-1.2.jar** 包含了JSTL的接口定义,定义了各种标签的API,比如`&lt;c:forEach&gt;`、...

      jstl-1.2.jar standard-1.1.2.jar

      `jstl-1.2.jar` 是JSTL 1.2版本的库文件,这个版本是在2004年发布的,增加了对JSR 152的支持,提供了对EL(Expression Language)的增强。 JSTL的核心组件包括以下几个部分: 1. **fmt**: 提供了日期、时间、数字的...

      jstl-1.2.jar包

      **JSTL 1.2.jar包详解** JavaServer Pages Standard Tag Library (JSTL) 是一个用于简化JavaWeb开发的库,它提供了一系列预定义的标签,使得开发者可以使用更简洁、更易于理解的方式编写JSP页面,而无需过多地接触...

      jstl-impl-1.2.jar和jstl-api-1.2.jar

      "jstl-impl-1.2.jar"和"jstl-api-1.2.jar"是JSTL 1.2版本的两个关键组件,它们在Java Web应用中起着至关重要的作用。 1. **jstl-api-1.2.jar**: 这个jar文件包含了JSTL的API接口定义。它定义了所有JSTL标签库的接口...

      jstl-1.2.rar_JSTL_jstl 1.2_jstl jar_jstl-1.1.2.jar _jstl.jar

      `jstl.jar` 文件是JSTL的核心库,包含了所有JSTL标签的实现。 标题中的"jstl-1.2.rar"是一个包含JSTL 1.2版本的压缩包,这个版本相对于早期的1.1.2版本进行了优化和增强,提供了更多的功能和更好的性能。`jstl-1.2....

      jstl1.2.zip

      《JSTL1.2深度解析与应用》 JSTL,全称为JavaServer Pages Standard Tag Library,是Java服务器页面标准标签库,是用于简化JavaWeb应用程序开发的一种强大的工具。在给定的“jstl1.2.zip”压缩包中,包含了四个核心...

      jstl-1.2.jar

      《深入理解JSTL:基于jstl-1.2.jar的实践指南》 JSTL,全称为JavaServer Pages Standard Tag Library,是Java服务器页面标准标签库,它为JSP开发提供了一系列预定义的标签,使得开发者可以更加便捷地进行页面逻辑...

      jstl-impl-1.2.jar

      jstl-api-1.2、jstl-impl-1.2.jar标签包,两份。

      jstl-api-1.2.jar jstl-impl-1.2.jar

      在提供的文件中,`jstl-api-1.2.jar` 和 `jstl-impl-1.2.jar` 是JSTL 1.2版本的两个关键组件: 1. **jstl-api-1.2.jar**:这个文件包含了JSTL的API接口定义。它定义了所有JSTL标签的接口和类,是开发者在编写JSP...

      JSTL包 jstl-1.2.jar standard.jar

      `jstl-1.2.jar`是JSTL 1.2版本的核心库,包含了JSTL Core和JSTL Functions这两个模块。JSTL Core提供了处理基本操作的标签,如迭代、条件判断、URL操作等。例如,`&lt;c:forEach&gt;`用于遍历集合,`&lt;c:if&gt;`和`&lt;c:choose&gt;`...

      javaee.jar,jsf-api.jar,jsf-impl.jar,jstl-1.2.jar

      4. **jstl-1.2.jar**:JSTL(JavaServer Pages Standard Tag Library)是一组预定义的标签库,用于简化JSP页面的开发。JSTL 1.2版本包括了核心标签、JDBC标签、XML标签和国际化的支持。这些标签可以用来处理常见任务...

      JSTL1.2.zip

      **JSTL 1.2 全面解析** JavaServer Pages Standard Tag Library(JSTL)是用于增强JavaWeb应用程序的标签库,它提供了一系列预定义的标签,可以帮助开发者更简洁、更高效地编写JSP页面,从而降低对脚本语言的依赖。...

      standard-1.1.2.jar,jstl-api-1.2.jar,jstl-impl-1.2.jar,jstl-1.2.jar

      Tomcat启动报错 java.lang.ClassNotFoundException: org.apache.jsp.index_jsp,检查你的项目中是否存在jsp-api.jar,jstl-api.jar,servlet-api.jar。

      jstl1.2.jar

      jstl1.2.jar.与jstl1.0的区别 例如 1.0&lt;%@ taglib uri="http://java.sun.com/jstl/core" prefix="c"%&gt; 1.2&lt;%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%&gt;

      jstl-api-1.2.jar

      **JSTL(JavaServer Pages Standard Tag Library)API 1.2详解** JSTL,全称为JavaServer Pages Standard Tag Library,是Java EE平台中一个用于简化JSP开发的库,它提供了一系列预定义的标签,帮助开发者在JSP页面...

    Global site tag (gtag.js) - Google Analytics