jstl

1. <c:out>:

<c:out value="hello world"></c:out>

<c:out value="${username}" default="没有值" escapeXml="false" ></c:out> 等同于request.getAttribute("user").toString();
<%

User u=new User();

u.setUsername("admin");

u.setPassword("admin");

request.setAttribute("user",u);

%>

<c:out value="${user.username}"></c:out> | |<c:out value="${user.password}"></c:out>

相当于(User) request.setAttribute("user").getUsername();

2. <c:set>:

<c:set var="abc" value="中国,北京" scope="request"></c:set>

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

3. <c:remove />

<c:remove var="abc"/> 移除 之后 中国北京将不再显示

4. <c:catch>:   

<c:catch var="err">

<%int i=3/0; %>

</c:catch>

<c:out value="${err.message}"></c:out>

5. <c:if>:

<%

request.setAttribute("a","hello");

request.setAttribute("age","22"); %>

判断字符串:

<c:if test="${a=='hello'}">

hello

</c:if>

判断数值

<c:if test="${age>12 and age<30 or age==22}">

年龄大于12 小于30 ${age }

</c:if>
<c:if test="${2<30?true:false}">ok</c:if>

6. <c:forEach>

<%

ArrayList<User> al=new ArrayList<User>();

User u1=new User();

u1.setUsername("陈超");

u1.setPassword("tiger");

User u2=new User();

u2.setUsername("system");

u2.setPassword("manager");

al.add(u1); al.add(u2);

request.setAttribute("alluser",al);

%>

<c:forEach items="${alluser}" var="u">

${u.username}

${u.password} <br/>

</c:forEach>
<%

Map map=new HashMap();

//map.put("aa","admin");

// map.put("bb","scott");

User u1=new User();

u1.setUsername("xiaoming");

u1.setPassword("xiaoming");

User u2=new User();

u2.setUsername("xiaoming");

u2.setPassword("xiaoming");

map.put("u1",u1);

map.put("u2",u2);

request.setAttribute("person",map);

%>

<c:forEach items="${person}" var="per">

key:${per.key }值 name: ${per.value.username }值 password:${per.value.password }<br/>

</c:forEach>
第一种迭代

<c:forEach var="i" begin="1" end="10">${i}&nbsp;&nbsp;</c:forEach> <br/>

第二种迭代

<c:forEach var="i" begin="1" end="10" step="3">${i}&nbsp;&nbsp;</c:forEach><br />

7. <c:forTokens>

用于分隔字符:
<c:forTokens items="11;33;44;52;" delims=";" var="temp">${temp}</c:forTokens>

 -----------------------优先级的问题----------------------------------------

<%

request.setAttribute("hello","request你好!");

session.setAttribute("hello","session你好!");

application.setAttribute("hello","application你好");

pageContext.setAttribute("hello","pageContext你们<a href='http://www.uu456.com'>百度</a>");

%>

这里有个优先级的问题,pageContext>request>session>application <c:out value="${hello}" default="没有值" escapeXml="false" >
escapeXml表示是否安装html样式显示 默认是true:表示以文本显示

 

----------------------------什么时候用$符,什么时候不用$------------------------------------

如果是从某个域对象中取出值,取的是一个变量就要用$ ,取的是一个固定的值就不要$

posted @ 2015-02-09 11:32  江湖一笑  阅读(149)  评论(0编辑  收藏  举报