*常用的标签,如<c:out>、<c:set>
*条件标签,如<c:if>,<c:choose>等
*URL标签,如<c:inport>等
*XML标签,如<xml:out>等
*国际化输出标签,如<fmt:timeZone>等
*SQL标签,如<sql:query>等
<fmt:setLocale value="zh-cn" />
<c:set var="customer" scope="session" value="${requestScope.customers}"/>
<c:forEach var="customer" items="${customers}">
<c:out value="${customer}"/><br>
</c:forEach>
<fmt:timeZone value="GMT">
<fmt:formatDate value="${now}" type="both" dateStyle="full"
timeStyle="full"/>
</fmt:timeZone>
一般用途的标签:
1.<c:out>
<c:out value="value" [escapeXml="{true|false}"] [default="defaultValue"]/>
<c:out value="2<10" escapeXml="true">
hgkjgkgj
</c:out>
<c:out>中的Body内容不会输出到客户端
<c:out value="${asdasd}" escapeXml="true">
defaultValue
</c:out>
<c:out>中的Body内容会输出到客户端
<c:out value="${notex}" default="这个值不存在"/>
2.<c:set>
1)<c:set value="value" var="varName" [scope="{page|request|session|application}"/>
2)<c:set var="varName" [scope="{page|request|session|application}">
bodyContent
</c:set>
3)<c:set value="value" target="target" property="propertyName"/>必须是JavaBean或者是Map对象
4)<c:set target="target" property="propertyName">
bodyContent
<c:set>
3.<c:remove>
<c:remove var="varName" [scope="{page|request|application}"]/>
如果没有指定范围相当于PageContext.removeAttribute(varName);
如果指定范围相当于PageContext.removeAttribute(varName, scope).
4.<c:catch>
<c:catch [var="varName"]>
nestedActions
</c:catch>
条件标签:
1.<c:if>
1)<c:if test="testCondition" var="varName" [scope="{page|request|application}"]/>
2)<c:if test="testCondition" var="varName" [scope="{page|request|application}"]>
BodyContent
</c:if>
2.<c:choose>
<c:choose>
BodyContent(<when> and <otherwise> subTag)
<c:choose/>
3.<c:when>
<c:when test="testCondition">
BodyContent
<c:when/>
4.<c:otherwise>
<c:otherwise>
conditional block
<c:ptherwise/>
迭代标签:
1.<c:forEach>
1)<c:forEach [var="varName"] items="collection" [varStatus="varStatusName"] [begin="begin"]
[end="end"] [step="step"]>
bodyContent
</c:forEach>
2)<c:forEach [var="varName"] [varStatus="varStatusName"] begin="begin"
end="end" [step="step"]>
bodyContent
</c:forEach>
下标从“0”开始的。
<c:forEach varStatus="status">
<c:out value="${status.index}">
<c:out value="${status.count}">
<c:out value="${status.first}">
<c:out value="${status.last}">
<c:forEach var="token" items="red,blue,green">
<c:out value="${token}"/>
</c:forEach>
2.<c:forTokens>
<c:forTokens items="StringOfTokens" delims="delimiters" [var="varName"]
[varStatus="varStatusName"] [begin="begin"] [end="end"] [step="step"]>
bodyContent
</c:forTokens>
delims分隔符可以是多个
URL相关的标签:
1.<c:import>
1)<c:import url="url" [context="context"] [var="varName"] [scope="{page|request|application}"]
[charEncoding="charEncoding"]>
optional body content for <c:param>subtags
</c:import>
2)<c:import url="url" [context="context"] varReader="varReaderName" [charEncoding="charEncoding"]>
body content where varReader is consumed by another action
</c:import>
varReader参数类型为Reader,用于读取资源
context当使用相对路径访问外部context资源时,context指定了这个资源的名字
<h3>绝对路径 URL</h3>
<c:import url="http://127.0.0.1:8080/ch15/beimport.jsp"/>
<h3>相对路径 URL</h3>
<c:import url="beimport.jsp"/>
<a href=<c:url value="beimport.jsp"><c:param name="userName" value="hellking"/></c:url>>--></a>
<c:import var="myurl" url="http://127.0.0.1:8080/ch15/beimport.jsp"/>
<blockquote>
<pre>
<c:out value="${myurl}"/>
</pre>
</blockquote>
<h3>string exposure relative URL:</h3>
<c:import var="myurl2" url="beimport.jsp"/>
<blockquote>
<pre>
<c:out value="${myurl2}"/>
</pre>
</blockquote>
<h3>传递参数到指定的URL</h3>
<blockquote>
<c:import url="beimport.jsp" charEncoding="gb2312">
<c:param name="userName" value="hellking"/>
</c:import>
</blockquote>
</ex:escapeHtml>应该是转义字符串中的html关键字,例如 <img> => <img>
2.<c:redirect>
1)<c:redirect url="value" [context="context"]/>
2)<c:redirect url="value" [context="context"]>
<c:param>subtags
</c:redirect>
3.<c:url>
1)<c:url value="value" [context="context"] [var="varName"] [scope="..."]/>
2)<c:url value="value" [context="context"] [var="varName"] [scope="..."]>
<c:param>subtags
</c:url>
4.<c:param>
1)<c:param name="name" value="value"/>
2)<c:param name="name">
param value
</c:param>
XML标签:
XML核心动作:
1.<x:parse>
1)<x:parse xml="XMLDocument" {var="var" [scope="scope"] | varDom="var" [scopeDom="scopeDom"]}
[systemId="systemId"] [filter="filter"]/>
2)<x:parse {var="var" [scope="scope"] | varDom="var" [scopeDom="scopeDom"]}
[systemId="systemId"] [filter="filter"]>
XML Document to parse
</x:parse>
2.<x:out>
<x:out select="XpathExpression" [escapeXml="{true|false}"]/>
escapeXml默认为true
<x:out select="$test/books//name"/><br>
<x:out select="$test//name"/><br>
<x:out select="$test/books/book/name"/><br>
效果一样
3.<x:set>
<x:set select="XPathException" var="varName" [scope="{...}"]/>
JSTL标签
最新推荐文章于 2023-08-15 22:40:43 发布