Jstl expression -c tag


Jstl expression -c tag

                                                 

1. Introduce tag 1

2. Property Details 1

3.<c:out/>2

4.<c:set/>2

5. <c:remove/>2

6. <c:catch/>2

7.<c:if/>2

8.<c:choose/>3

9.<c:import/>3

10.<c:forEach>3

11. <c:forTokens>4

12. <c:param/>4

13. <c:redirect/>5

14. <c:url/>5

 

1.Introduce tags

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

2. Property Details

Attributes

describe

value

what to output

default

output default value

escapeXml

Whether to ignore XML special characters

target

The object to which the property to be modified belongs

property

property to modify

where

variable to store information

scope

Scope of the var property

test

condition

url

The URL of the resource to be imported, which can be a relative path or an absolute path, and can import other host resources

context

When using a relative path to access an external context resource, the context specifies the name of the resource.

charEncoding

the character encoding set of the incoming data

varReader

optional variable used to provide a java.io.Reader object

items

information to be looped

begin

element to start with (0=first element, 1=second element)

end

last element (0=first element, 1=second element)

step

step size for each iteration

varStatus

The variable name representing the loop state

delims

delimiter

 

3.<c:out/>

The <c:out> tag is used to display the result of an expression, similar to <%= %>, except that the <c:out> tag can directly access properties through the "." operator.

Example :

<c:out value="string" default="string" escapeXml="true|false"/>

4.<c:set/>

The <c:set> tag is used to set variable values ​​and object properties.

The <c:set> tag is the twin brother of the <jsp:setProperty> behavior tag.

This tag is useful because it evaluates the expression and then uses the result to set the value of the JavaBean object or java.util.Map object .

If the target attribute is specified, the property attribute also needs to be specified

Example :

<c:set

   var="string"

   value="string"

   target="string"

   property="string"

   scope="string"/>

5.<c:remove/>

<c:remove>标签用于移除一个变量,可以指定这个变量的作用域,若未指定,则默认为变量第一次出现的作用域。

这个标签不是特别有用,不过可以用来确保JSP完成清理工作。

实例:

<c:remove var="string" scope="string"/>

6.<c:catch/>

<c:catch> 标签主要用来处理产生错误的异常状况,并且将错误信息储存起来。

实例:

<c:catch var="<string>">

...

</c:catch>

<c:catch var ="catchException">

   <% int x = 5/0;%></c:catch>

<c:if test = "${catchException != null}">

   <p>异常为 : ${catchException} <br />

   发生了异常: ${catchException.message}</p></c:if>

7.<c:if/>

<c:if>标签判断表达式的值,如果表达式的值为 true 则执行其主体内容。

实例:

<c:if test="boolean" var="string" scope="string">

 ...</c:if>

8.<c:choose/>

<c:choose>标签与Java switch语句的功能一样,用于在众多选项中做出选择。

switch语句中有case,而<c:choose>标签中对应有<c:when>switch语句中有default,而<c:choose>标签中有<c:otherwise>

实例:

<c:choose>

    <c:when test="<boolean>"/>

        ...

    </c:when>

    <c:when test="<boolean>"/>

        ...

    </c:when>

    ...

    ...

    <c:otherwise>

        ...

</c:otherwise>

</c:choose>

9.<c:import/>

<c:import>标签提供了所有<jsp:include>行为标签所具有的功能,同时也允许包含绝对URL。

举例来说,使用<c:import>标签可以包含一个FTP服务器中不同的网页内容。

实例:

<c:import

   url="string"

   var="string"

   scope="string"

   varRender="string"

   context="string"

   charEncoding="string"/>

10.<c:forEach>

这些标签封装了Java中的for,while,do-while循环。

相比而言,<c:forEach>标签是更加通用的标签,因为它迭代一个集合中的对象。

实例:

<c:forEach

    items="object"

    begin="int"

    end="int"

    step="int"

    var="string"

    varStatus="string"></c:forEach>

 

11.<c:forTokens>

<c:forTokens>标签通过指定分隔符将字符串分隔为一个数组然后迭代它们。

<c:forTokens>标签与<c:forEach>标签有相似的属性,不过<c:forTokens>还有另一个属性

实例:

<c:forTokens

    items="string"

    delims="string"

    begin="int"

    end="int"

    step="int"

    var="string"

varStatus="string"></c:forTokens>

<c:forTokens items="google,runoob,taobao" delims="," var="name">

   <c:out value="${name}"/><p>

</c:forTokens>

12.<c:param/>

<c:param>标签用于在<c:url>标签中指定参数,而且与URL编码相关。

<c:param>标签内,name属性表明参数的名称,value属性表明参数的值。

实例:

<c:param name="<string>" value="<string>"/>

name:URL中要设置的参数名称

value:参数的值

<c:url var="myURL" value="main.jsp">

<c:param name="name" value="Runoob"/>

<c:param name="url" value="www.runoob.com"/>

</c:url>

<a href="/<c:out value="${myURL}"/>">

 

13.<c:redirect/>

<c:redirect>标签通过自动重写URL来将浏览器重定向至一个新的URL,它提供内容相关的URL,并且支持c:param标签。

实例:

<c:redirect url="<string>" context="<string>"/>

 

14.<c:url/>

<c:url>标签将URL格式化为一个字符串,然后存储在一个变量中。

这个标签在需要的时候会自动重写URL。

var属性用于存储格式化后的URL。

<c:url>标签只是用于调用response.encodeURL()方法的一种可选的方法。它真正的优势在于提供了合适的URL编码,包括<c:param>中指定的参数。

实例:

<c:url

  var="<string>"

  scope="<string>"

  value="<string>"

  context="<string>"/>

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326654543&siteId=291194637