`
weigang.gao
  • 浏览: 497063 次
  • 性别: Icon_minigender_1
  • 来自: 上海
文章分类
社区版块
存档分类
最新评论

jstl标签

    博客分类:
  • jstl
 
阅读更多


1.准备jstl
   到http://archive.apache.org/dist/jakarta/taglibs/standard/binaries/下载jakarta-taglibs-standard-1.1.2.zip
解压后成为jakarta-taglibs-standard-1.1.2 
2.准备web开发目录
   比如我的web目录系统默认目录%tomcat_home%\webapps\ROOT下,工作目录为ROOT,也可以自定义工作目录,但必须要保证工作目录下建立WEB-INF\lib,WEB-INF\classes 
3.拷贝.jar文件
   将jakarta-taglibs-standard-1.1.2\lib\下的两个jar文件:standard.jar和jstl.jar文件拷贝到工作目录的\WEB-INF\lib\下 
4.拷贝.tld文件(可选)
 将jakarta-taglibs-standard-1.1.2\tld\下的15个tld类型文件拷到"Working folder\WEB-INF\tld"下 
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/tld/fmt.tld</taglib-location>
</taglib> 
<taglib>
    <taglib-uri>http://java.sun.com/jstl/fmt-1_0</taglib-uri>
    <taglib-location>/WEB-INF/tld/fmt-1_0.tld</taglib-location>
</taglib>
<taglib>
    <taglib-uri>http://java.sun.com/jstl/fmt-1_0-rt</taglib-uri>
    <taglib-location>/WEB-INF/tld/fmt-1_0-rt.tld</taglib-location>
</taglib> 
<taglib>
    <taglib-uri>http://java.sun.com/jstl/core</taglib-uri>
    <taglib-location>/WEB-INF/tld/c.tld</taglib-location>
</taglib> 
<taglib>
    <taglib-uri>http://java.sun.com/jstl/core-1_0-rt</taglib-uri>
    <taglib-location>/WEB-INF/tld/c-1_0-rt.tld</taglib-location>
</taglib> 
<taglib>
    <taglib-uri>http://java.sun.com/jstl/core-1_0</taglib-uri>
    <taglib-location>/WEB-INF/tld/c-1_0.tld</taglib-location>
</taglib> 
<taglib>
    <taglib-uri>http://java.sun.com/jstl/sql</taglib-uri>
    <taglib-location>/WEB-INF/tld/sql.tld</taglib-location>
</taglib> 
<taglib>
    <taglib-uri>http://java.sun.com/jstl/sql-1_0</taglib-uri>
    <taglib-location>/WEB-INF/tld/sql-1_0.tld</taglib-location>
</taglib> 
<taglib>
    <taglib-uri>http://java.sun.com/jstl/sql-1_0-rt</taglib-uri>
    <taglib-location>/WEB-INF/tld/sql-1_0-rt.tld</taglib-location>
</taglib> 
<taglib>
    <taglib-uri>http://java.sun.com/jstl/x</taglib-uri>
    <taglib-location>/WEB-INF/tld/x.tld</taglib-location>
</taglib> 
<taglib>
    <taglib-uri>http://java.sun.com/jstl/x-1_0</taglib-uri>
    <taglib-location>/WEB-INF/tld/x-1_0.tld</taglib-location>
</taglib> 
<taglib>
    <taglib-uri>http://java.sun.com/jstl/x-1_0-rt</taglib-uri>
    <taglib-location>/WEB-INF/tld/x-1_0-rt.tld</taglib-location>
</taglib> 
<taglib>
    <taglib-uri>http://java.sun.com/jstl/fn</taglib-uri>
    <taglib-location>/WEB-INF/tld/fn.tld</taglib-location>
</taglib> 
<taglib>
    <taglib-uri>http://java.sun.com/jstl/permittedTaglibs</taglib-uri>
    <taglib-location>/WEB-INF/tld/permittedTaglibs.tld</taglib-location>
</taglib> 
<taglib>
    <taglib-uri>http://java.sun.com/jstl/scriptfree</taglib-uri>
    <taglib-location>/WEB-INF/tld/scriptfree.tld</taglib-location>
</taglib>
</web-app> 
  
提示: 
In addition to declaring the tag libraries, tutorial examples access the JSTL API and implementation. In the Application Server, the JSTL TLDs and libraries are distributed in the archive <J2EE_HOME>/lib/appserv-jstl.jar. This library is automatically loaded into the classpath of all web applications running on the Application Server, so you don't need to add it to your web application. 

  
以上摘自j2ee的tutorial,说明步骤四、五中的TLD文件注册部分是可以省略的,WEB工程能自动的从jar包中加载相应的标签库。 

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.显示结果:
欢迎测试你的第一个使用到JSTL 的网页
你使用的浏览器是:
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SailBrowser; .NET CLR 1.1.4322) David O'Davies
8.注意的问题
主要的一个问题还是路径的问题,笔者配置了好几次都不能成功,就是把工作目录给弄错了,把项目的目录误认为是工作目录,一直在项目的目录下配置文件,其实应该在工作目录下配置,当然可以把工作目录改成项目的目录,问题也就可以解决了。
9.常出现的问题和提示:
org.apache.jasper.JasperException: The absolute uri: http://java.sun.com/jstl/core cannot be resolved in either web.xml or the jar files deployed with this application
出现这个问题主要一种可能是工作目录的\WEB-INF\lib\下缺少standard.jar和jstl.jar文件,另外一种可能是web.xml没有进行TAG的正确配置。
According to TLD or attribute directive in tag file, attribute value does not accept any expressions
应用部署运行的时候出现JSP异常, 发生在使用JSTL库的时候: According to TLD or attribute directive in tag file, attribute value does not accept any expressions, 可能是因为使用了JSP2.0版本, 同时又没有使用JSTL core库的备用版本(RT库), 以下有两种处理方法: 
a. 修改web.xml. 
<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">
改为2.3版本的 
<!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>
b. 使用JSTL core RT库 
JSTL core库的有两种taglib伪指令, 其中RT库即是依赖于JSP传统的请求时属性值, 而不是依赖于EL来实现(称为EL库.JSP2.0将支持EL) 
JSP中使用<%@ taglib uri=http://java.sun.com/jstl/core prefix="c"%>在2.3版本都可以,在2.4就不行了, 难道是版本不兼容吗? 
只要将 
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c"%>
改为 
<%@ taglib uri=http://java.sun.com/jstl/core_rt prefix="c"%>
就没有问题了 
三、标签的使用 
C标准标签库
Taglib-http://java.sun.com/jstl/core
基础:
1.jsp页面引入C标签库:
<@taglib uri=”http://java.sun.com/jstl/core” prefix=”c”>   //引入标签库 前缀为c
2.c标签库的标签列表
    
C标签库例举
标签名   用处
<c:choose>   
<c:forEach>   
<c:forTokens>   
<c:if>   
<c:import>   
<c:otherwise>   
<c:out>   把对象的数值输出到JspWriter
<c:p

分享到:
评论

相关推荐

    JAVAEE实验报告EL表达式和jstl标签库的使用.pdf

    JAVAEE 实验报告 EL 表达式和 JSTL 标签库的使用 EL 表达式(Expression Language)是一种在 JSP 页面中使用的脚本语言,用于简化 JSP 页面的开发。EL 表达式可以访问 JSP 页面中的变量、对象和集合,进行逻辑操作...

    JSTL标签库依赖,内含Tomcat8、Tomcat10所需JSTL依赖

    3. 使用JSTL标签:现在可以在JSP页面中使用JSTL标签,如`&lt;c:forEach&gt;`进行迭代,`&lt;c:if&gt;`进行条件判断,`&lt;fmt:formatDate&gt;`格式化日期等。 总之,JSTL是提升JSP页面编写效率的重要工具,而依赖注入则是现代Java应用...

    JSTL标签库-tomcat10-简化JSP中java代码

    **正文** JSTL(JavaServer Pages Standard Tag Library)是Java Web开发中一个重要的标签库,主要用于简化...通过学习和实践这些内容,开发者可以更加熟练地在JSP页面中运用JSTL标签,提升Web应用的开发质量和效率。

    JSTL标签库需要导入的Jar包

    以下是关于JSTL标签库所需导入的JAR包及其功能的详细解释: 1. **jstl.jar**:这是核心JSTL库,包含了大部分常用的标签,如 `&lt;c:if&gt;`, `&lt;c:forEach&gt;`, `&lt;fmt:formatDate&gt;` 等。这些标签提供了条件判断、循环、格式...

    jstl标签使用文档,jstl标签使用帮助文档

    本文档将详细介绍JSTL标签的使用方法,帮助开发者更好地理解和应用。 JSTL主要分为五个核心部分: 1. **Core(核心标签库)**:提供基本的控制结构,如条件语句、循环、跳转等。 - `&lt;c:if&gt;`:用于执行条件判断。 ...

    jstl标签库的配置

    本篇文章将深入探讨JSTL标签库的配置过程及其在实际应用中的作用。 首先,我们要理解**JSTL的核心组件**。JSTL主要由五个核心部分组成:Core、Format、I18N、SQL和XML。其中,Core组件包含了大部分用于控制流程、...

Global site tag (gtag.js) - Google Analytics