JSTL 详解02

<c:forTokens>

<c:forTokens items="stringOfTokens " delims="delimiters "

[var="varName "]

[varStatus="varStatusName "]

[begin="begin "] [end="end "] [step="step "]>

body content

</c:forTokens>

参数说明:

Items :要输出的变量

Delims :以什么为分隔符

Var :保存每次循环出的变量

如:

Java代码
  1. //测试c:forTokens   
  2. request.setAttribute("strTokens""1,2,3,4,5,6" );  
//测试c:forTokens
request.setAttribute("strTokens", "1,2,3,4,5,6");

 

Html代码
  1. < c:forTokens   items = "${strTokens}"   delims = ","   var = "v" >   
  2.     ${v }  
  3. </ c:forTokens >   
<c:forTokens items="${strTokens}" delims="," var="v">
    ${v }
</c:forTokens>

 

 

 

 

以上以 , 为分隔符将变量循环输出

 

 

URL Related Actions

<c:import>

Syntax 1: Resource content inlined or exported as a String object

<c:import url=”url ” [context=”context ”]

[var=”varName ”] [scope=”{page|request|session|application}”]

[charEncoding=”charEncoding ”]>

optional body content for <c:param> subtags

</c:import>

Syntax 2: Resource content exported as a Reader object

<c:import url=”url ” [context=”context ”]

varReader=”varReaderName

[charEncoding=”charEncoding ”]>

body content where varReader is consumed by another action

</c:import>

参数说明:

Context :指定工程路径

url :精确到页面

如:

Html代码
  1. < li > 测试c:import </ li > < br >   
  2.     < c:import   url = "http://localhost:8080/struts_login/index.jsp" />   
  3. < p >   
<li>测试c:import</li><br>
    <c:import url="http://localhost:8080/struts_login/index.jsp"/>
<p>

 

 

 

直接在 URL 上指定精确页面也是可以的,但这样就写死了代码

 

<c:url>

 

Syntax 1: Without body content

<c:url value=”value” [context=”context ”]

[var=”varName ”] [scope=”{page|request|session|application}”]/>

Syntax 2: With body content to specify query string parameters

<c:url value=”value” [context=”context ”]

[var=”varName ”] [scope=”{page|request|session|application}”]>

<c:param> subtags

</c:url>

Value :要提交参数的页面

Var :最后组成的 URL

如:

Html代码
  1. < c:url   value = "http://localhost:8080/drp/sysmgr/user_add.jsp"   var = "v" >   
  2.     < c:param   name = "username"   value = "Jack" />   
  3.     < c:param   name = "age"   value = "20" />   
  4. </ c:url >   
  5. ${v }  
<c:url value="http://localhost:8080/drp/sysmgr/user_add.jsp" var="v">
    <c:param name="username" value="Jack"/>
    <c:param name="age" value="20"/>
</c:url>
${v }

 

 

 

最后组成了一个 URL ,可以看输出

<c:param>

Syntax 1: Parameter value specified in attribute “value”

<c:param name=”name ” value=”value ”/>

Syntax 2: Parameter value specified in the body content

<c:param name=”name ”>

parameter value

</c:param>

 

<c:redirect>

Syntax 1: Without body content

<c:redirect url=”value ” [context=”context ”]/>

Syntax 2: With body content to specify query string parameters

<c:redirect url=”value ” [context=”context ”]/>

<c:param> subtags

</c:redirect>

标签说明:页面将重定向到一个新页面,重定向时还可以传递参数过去

 

 

Formatting Actions

<fmt:parseDate>

Syntax 1: without a body

<fmt:parseDate value=”dateString”

[type=”{time|date|both}”]

[dateStyle=”{default|short|medium|long|full} ]

[timeStyle=”{default|short|medium|long|full} ]

[pattern=”customPattern ”]

[timeZone=”timeZone ”]

[parseLocale=”parseLocale ”]

[var=”varName ”]

[scope=”{page|request|session|application}”]/>

Syntax 2: with a body to specify the date value to be parsed

<fmt:parseDate [type=”{time|date|both}”]

[dateStyle=”{default|short|medium|long|full} ]

[timeStyle=”{default|short|medium|long|full} ]

[pattern=”customPattern ”]

[timeZone=”timeZone ”]

[parseLocale=”parseLocale ”]

[var=”varName ”]

[scope=”{page|request|session|application}”]>

date value to be parsed

</fmt:parseDate>

参数说明:

Value :要格式化的值

Type :显示类型,如只显示时间,只显示日期

dateStyle :日期的显示类型

timeStyle :时间的显示类型

pattern :怎样显示格式化后的日期,直接设置该属性即可

如:

Html代码
  1. < fmt:formatDate   value = "${today}" />   
  2. < fmt:formatDate   value = "${today}"   type = "date" />   
  3. < fmt:formatDate   value = "${today}"   type = "time" />   
  4. < fmt:formatDate   value = "${today}"   type = "both" />   
  5. < fmt:formatDate   value = "${today}"   dateStyle = "short" />   
  6. < fmt:formatDate   value = "${today}"   dateStyle = "medium" />   
  7. < fmt:formatDate   value = "${today}"   dateStyle = "long" />   
  8. < fmt:formatDate   value = "${today}"   dateStyle = "full" />   
  9. < fmt:formatDate   value = "${today}"   pattern = "yyyy/MM/dd HH:mm:ss" />   
  10. < fmt:formatDate   value = "${today}"   pattern = "yyyy/MM/dd HH:mm:ss"   var = "d" />   
  11. ${d }  
<fmt:formatDate value="${today}"/>
<fmt:formatDate value="${today}" type="date"/>
<fmt:formatDate value="${today}" type="time"/>
<fmt:formatDate value="${today}" type="both"/>
<fmt:formatDate value="${today}" dateStyle="short"/>
<fmt:formatDate value="${today}" dateStyle="medium"/>
<fmt:formatDate value="${today}" dateStyle="long"/>
<fmt:formatDate value="${today}" dateStyle="full"/>
<fmt:formatDate value="${today}" pattern="yyyy/MM/dd HH:mm:ss"/>
<fmt:formatDate value="${today}" pattern="yyyy/MM/dd HH:mm:ss" var="d"/>
${d }

 

 

 

如果设置了保存的变量值就不会在直接显示了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值