• jstl 部分标签


    来源:[jstl标签]

    c:remove 删除变量

    c:remove标签删除变量,无论是从指定的范围内或范围内的变量(如果没有指定范围)。这个动作通常是不特别有帮助,但它可以帮助确保一个JSP范围内的资源,它负责清理。

    属性 描述 必选 默认
    var 删除的变量名称 Yes None
    scope 要删除变量的范围 No All scopes

    实例:

    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
    <html>
    <head>
    <title><c:remove> Tag Example</title>
    </head>
    <body>
    <c:set var="salary" scope="session" value="${2000*2}"/>
    <p>Before Remove Value: <c:out value="${salary}"/></p>
    <c:remove var="salary"/>
    <p>After Remove Value: <c:out value="${salary}"/></p>
    </body>
    </html>
    
    Before Remove Value: 4000
    After Remove Value: 	 
    

    c:catch 捕获任何Throwable

    c:catch标签捕获任何Throwable,发生在它的身上,有选择地公开。简单地用于错误处理,更优雅地处理这个问题。

    属性 描述 必选 默认
    var 变量的名称保存在java.lang。如果抛出的Throwable在body元素内。 No None

    实例:

    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
    <html>
    <head>
    <title><c:catch> Tag Example</title>
    </head>
    <body>
    
    <c:catch var ="catchException">
       <% int x = 5/0;%>
    </c:catch>
    
    <c:if test = "${catchException != null}">
       <p>The exception is : ${catchException} <br />
       There is an exception: ${catchException.message}</p>
    </c:if>
    
    </body>
    </html>
    
    The exception is : java.lang.ArithmaticException: / by zero
    There is an exception: / by zero 
    

    c:import 导入内容

    c:import标记提供include的所有的功能动作,但也可以包含绝对URL。例如,允许使用导入标签包含的内容从一个不同的Web站点或FTP服务器。

    属性 描述 必需 默认值
    url URL检索和导入到页面 Yes None
    context /后面的本地Web应用程序的名称 No 目前的应用
    charEncoding 为导入数据使用的字符集 No ISO-8859-1
    var 变量的名称存储导入的文本 No Print to page
    scope 变量作用域用于存储导入的文本 No Page
    varReader 替代变量的名称,暴露的java.io.Reader No None

    实例:

    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
    <html>
    <head>
    <title><c:import> Tag Example</title>
    </head>
    <body>
    <c:import var="data" url="http://www.xxxxxx.com"/>
    <c:out value="${data}"/>
    </body>
    </html>
    
    将获取完整的内容从xxxxxx.com/index.html和存储在可变数据最终将被打印 
    

    c:param key value键值对

    c:param标签允许适当的URL请求参数到指定的URL和任何必要的URL编码。
    在一个c:param标签的name属性表示参数的名称,value属性表示的参数值。

    属性 描述 必需 默认值
    name 在URL中设置的请求参数的名称 Yes None
    value 在URL中设置的请求参数的值 No Body

    实例:

    如果您需要将参数传递到一个<c:import>标记,使用<c:url>标记创建的URL如下所示:
    
    <c:url value="/index.jsp" var="myURL">
       <c:param name="trackingId" value="1234"/>
       <c:param name="reportType" value="summary"/>
    </c:url>
    <c:import url="${myURL}"/>
    上述要求,将通过的URL如下。
    
    "/index.jsp?trackingId=1234;reportType=summary" 
    

    fn:escapeXml 函数转义字符

    fn:escapeXml() 函数的语法
    使用fn:escapeXml()函数转义字符,可以解释为XML标记。

    java.lang.String escapeXml(java.lang.String)

    实例:

    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
    <%@ taglib uri="http://java.sun.com/jsp/jstl/functions" 
                                                      prefix="fn" %>
    <html>
    <head>
    <title>Using JSTL Functions</title>
    </head>
    <body>
    
    <c:set var="string1" value="This is first String."/>
    <c:set var="string2" value="This <abc>is second String.</abc>"/>
    
    <p>With escapeXml() Function:</p>
    <p>string (1) : ${fn:escapeXml(string1)}</p>
    <p>string (2) : ${fn:escapeXml(string2)}</p>
    
    <p>Without escapeXml() Function:</p>
    <p>string (1) : ${string1}</p>
    <p>string (2) : ${string2}</p>
    
    </body>
    </html>
    
    
    
    With escapeXml() Function: 
    
    string (1) : This is first String. 
    
    string (2) : This <abc>is second String.</abc> 
    
    Without escapeXml() Function: 
    
    string (1) : This is first String. 
    
    string (2) : This is second String. 
    

    fn:join() 函数将所有的数组中的元素转换成字符串与一个指定的分隔符。

    fn:join() 函数将所有的数组中的元素转换成字符串与一个指定的分隔符。

    fn:join() 函数有以下语法:

    String join (java.lang.String[], java.lang.String)

    实例:

    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
    <%@ taglib uri="http://java.sun.com/jsp/jstl/functions" 
                                                      prefix="fn" %>
    <html>
    <head>
    <title>Using JSTL Functions</title>
    </head>
    <body>
    
    <c:set var="string1" value="This is first String."/>
    <c:set var="string2" value="${fn:split(string1, ' ')}" />
    <c:set var="string3" value="${fn:join(string2, '-')}" />
    
    <p>Final String : ${string3}</p>
    
    </body>
    </html>
    
    Final String : This-is-first-String.
    

    fn:substringAfter() 函数返回一个字符串的一部分,在指定的子串后面部分。

    fn:substringAfter() 函数返回一个字符串的一部分,在指定的子串后面部分。

    fn:substringAfter() 函数有以下语法:

    java.lang.String substringAfter(java.lang.String, java.lang.String)

    实例:

    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
    <%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
    <html>
    <head>
    <title>Using JSTL Functions</title>
    </head>
    <body>
    
    <c:set var="string1" value="This is first String."/>
    <c:set var="string2" value="${fn:substringAfter(string1, 'is')}" />
    
    <p>Final sub string : ${string2}</p>
    
    </body>
    </html>
    
    Final sub string : is first String.
    

    fn:substringBefore() 函数返回一个字符串的一部分,在指定的子串之前。

    fn:substringBefore() 函数返回一个字符串的一部分,在指定的子串之前。

    fn:substringBefore() 函数具有以下语法:

    java.lang.String substringBefore(java.lang.String, java.lang.String)

    实例:

    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
    <%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
    <html>
    <head>
    <title>Using JSTL Functions</title>
    </head>
    <body>
    
    <c:set var="string1" value="This is first String."/>
    <c:set var="string2" value="${fn:substringBefore(string1, 'first')}" />
    
    <p>Final sub string : ${string2}</p>
    
    </body>
    </html>
    
    Final sub string : This is 
    

    fn:contains() 判断输入的字符串是否包含指定的子串。

    fn:substringBefore() 判断输入的字符串是否包含指定的子串。

    使用fn:contains()函数的语法如下:

    boolean contains(java.lang.String, java.lang.String)

    实例:

    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
    <%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
    <html>
    <head>
    <title>Using JSTL Functions-www.yiibai.com</title>
    </head>
    <body>
    
    <c:set var="theString" value="I am a test String"/>
    
    <c:if test="${fn:contains(theString, 'test')}">
       <p>Found test string<p>
    </c:if>
    
    <c:if test="${fn:contains(theString, 'TEST')}">
       <p>Found TEST string<p>
    </c:if>
    
    </body>
    </html>
    
    Found test string
  • 相关阅读:
    CODEVS——T 2618 核电站问题
    Spring使用AspectJ注解和XML配置实现AOP
    oracle存储过程
    oracle什么时候需要commit
    短信发送接口被恶意访问
    JAVA内存模型
    构造函数,静态代码块,构造代码块
    mybatis缓存
    volatile和synchronized
    利用反射创建对象必须要显式的声明构造方法吗?
  • 原文地址:https://www.cnblogs.com/cuiyf/p/6530355.html
Copyright © 2020-2023  润新知