jsp标准标签库

1.c:out标签用于向浏览器输出数据,一般要结合default属性使用

1 <c:set value="chichao" var="data" scope="request"></c:set>

2.c:set标签用于设置域或者map,javabean的属性值

 1  <c:set value="chichao" var="data" scope="request"></c:set>
2 ${data}
3 <%
4 Map map = new HashMap();
5 request.setAttribute("map",map);
6 %>
7 <c:set value="chichao" target="${map}" property="data"></c:set>
8 ${map.data }
9 <%
10 cnblogs.xiaoqiu.domain.Person p = new cnblogs.xiaoqiu.domain.Person();
11 request.setAttribute("person",p);
12 %>
13 <c:set value="chichao" target="${person}" property="name"></c:set>
14 ${person.name }

3.c:foreach标签的特殊用法

 1  <%--c:foreach标签输出连续数字--%>
2 <c:forEach var="pageCode" begin="1" end="8" step="1">
3 ${pageCode}
4 </c:forEach>
5 <%--c:foreach标签实现表格间色--%>
6 <style>
7 .odd{background-color:red;}
8 .even{background-color:yellow;}
9 tr:hover{background-color:blue;}
10 </style>
11 <%
12 List list = new ArrayList();
13 list.add("chichao");
14 list.add("chichao");
15 list.add("chichao");
16 list.add("chichao");
17 request.setAttribute("list",list);
18 %>
19 <table>
20 <c:forEach var="context" items="${list}" varStatus="status">
21 <tr class="${status.count%2==0?'odd':'even' }">
22 ${context }
23 </tr>
24 </c:forEach>
25 </table>

4.c:url标签用于实现url重写:

1 <c:url var="url" value="/jstl/1.jsp">
2 <c:param name="userName" value="chichao"></c:param>
3 </c:url>
4 <a href="${url}">跳转</a>

5.c:forTokens标签用于实现分割字符串:

1 <%
2 request.setAttribute("data","a,s,d,f");
3 %>
4 <c:forTokens var="data" items="${data}" delims=",">${data}</c:forTokens>





posted @ 2012-01-25 18:55  xiao秋  阅读(762)  评论(0编辑  收藏  举报