JSTL下载配置

6 篇文章 0 订阅

JSTL下载地址:http://download.csdn.net/source/3442194

配置说明如下:

1.首先将解压的文件进行解压,其中lib、tld是我们项目中要用到的。

2.将lib中的jar导入项目中。

3.在WEB-INF同级目录下新建tlds文件夹,并将tld中所有文件拷贝到其中。

4.配置web.xml:

<web-app version="3.0" 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_3_0.xsd">
    <jsp-config>
        <taglib>
            <taglib-uri>http://java.sun.com/jsp/jstl/core</taglib-uri>
            <taglib-location>/tlds/c.tld</taglib-location>
        </taglib>
    </jsp-config>
</web-app>
jsp-config标签只需放在web-app的根元素下即可。

taglib-uri的值决定了在JSP中引用标签库时所指定的URL。


5.实例使用

<%-- 
    Document   : newjsp
    Created on : 2011-7-14
    Author     : Mr.Jin
--%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        一般用途的标签:c:out, c:set, c:remove, c:catch
        <c:set var="varaible" value="myTest"/>
        <c:out default="hello world" value="test"/>
        ${varaible}
        <c:remove var="varaible"/>
        <c:out default="novar" value="${varaible}"/>
        
        //----------------------------------------------------------------------
        
        条件标签:c:if, c:choose, c:when, c:otherwise
        <c:if test="${5<7}" var="result">
        body content
        </c:if>
        
        <c:out value="${result}"/>表达式计算结果
        
        
        <!--用于条件选择,它和c:when以及c:otherwise一起使用-->
        <!--c:when代表c:choose的一个分支-->
        <!--c:otherwise,必须以c:choose作为它的父标签,必须是c:choose的最后分支-->
        <c:choose>
            <c:when test="3>4">3确实大于4</c:when>
            <c:when test="4>5">4确实大于5</c:when>
            <c:otherwise>
                以上条件均不正确,这otherwise相当于default。
            </c:otherwise>
        </c:choose>
        //----------------------------------------------------------------------

        
        迭代标签:c:forEach,c:forTokens
        c:forEach,在一个包含一等系列对象的Collection中迭代计算它的bodyContent,或者重复迭代固定的次数
        按固定次数迭代
        <c:forEach begin="0" end="4" step="1">
            <br/>for each item
        </c:forEach>
        
        按集合迭代
        <c:forEach var="varName" items="collection">
            ${varName}
        </c:forEach>
        //----------------------------------------------------------------------
        URL相关的标签c:import,c:redirect,c:url,c:param
    </body>
</html>




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值