Jstl expression -c tag
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
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 |
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"/>
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"/>
<c:remove>标签用于移除一个变量,可以指定这个变量的作用域,若未指定,则默认为变量第一次出现的作用域。
这个标签不是特别有用,不过可以用来确保JSP完成清理工作。
实例:
<c:remove var="string" scope="string"/>
<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>
<c:if>标签判断表达式的值,如果表达式的值为 true 则执行其主体内容。
实例:
<c:if test="boolean" var="string" scope="string">
...</c:if>
<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>
<c:import>标签提供了所有<jsp:include>行为标签所具有的功能,同时也允许包含绝对URL。
举例来说,使用<c:import>标签可以包含一个FTP服务器中不同的网页内容。
实例:
<c:import
url="string"
var="string"
scope="string"
varRender="string"
context="string"
charEncoding="string"/>
这些标签封装了Java中的for,while,do-while循环。
相比而言,<c:forEach>标签是更加通用的标签,因为它迭代一个集合中的对象。
实例:
<c:forEach
items="object"
begin="int"
end="int"
step="int"
var="string"
varStatus="string"></c:forEach>
<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>
<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}"/>">
<c:redirect>标签通过自动重写URL来将浏览器重定向至一个新的URL,它提供内容相关的URL,并且支持c:param标签。
实例:
<c:redirect url="<string>" context="<string>"/>
<c:url>标签将URL格式化为一个字符串,然后存储在一个变量中。
这个标签在需要的时候会自动重写URL。
var属性用于存储格式化后的URL。
<c:url>标签只是用于调用response.encodeURL()方法的一种可选的方法。它真正的优势在于提供了合适的URL编码,包括<c:param>中指定的参数。
实例:
<c:url
var="<string>"
scope="<string>"
value="<string>"
context="<string>"/>