标签:
<br/>----------------获取域中存的数据-------------------------<br/>
<%
String data = "abcd";
request.setAttribute("data",data);
%>
${data} <%--pageContext.findAttribute("data") ""--%>
<br/>----------------获取域中存的javabean的数据----------------<br/>
<%
Person p = new Person();
p.setName("aaaa");
request.setAttribute("person",p);
%>
${person.name } <!--根据get方法来获取,而不是Person类中的属性 -->
<br/>----------------获取域中存的javabean中的javabean的数据-----<br/>
<%
Person p1 = new Person();
Address a = new Address();
a.setCity("上海");
p1.setAddress(a);
request.setAttribute("p1",p1);
%>
${p1.address.city }
<br/>----------------获取域中存的list集合中的数据-----------------<br/>
<%
List list = new ArrayList();
list.add(new Person("aaa"));
list.add(new Person("bbb"));
request.setAttribute("list",list);
%>
${list[‘1‘].name } <!--.取不到就用[] -->
<br/>----------------获取域中map集合中的数据--------------------<br/>
<%
Map map = new HashMap();
map.put("aa",new Person("aaaaa"));
map.put("bb",new Person("bbbbb"));
map.put("cc",new Person("ccccc"));
map.put("dd",new Person("ddddd"));
map.put("111",new Person("eeeee"));
request.setAttribute("map111",map);
%>
${map111.cc.name }
<br/>----------------常用的一个el表达式-------------------------<br/>
${pageContext.request.contextPath }
<a href="${pageContext.request.contextPath }/index.jsp">点点</a>
1、语法:${运算表达式},EL表达式支持如下运算符(还有加减乘除等运算符,但是不支持字符串拼接,像个bug)
<br/>----------------运算符-------------------------<br/>
<%
request.setAttribute("username","aaa");
request.setAttribute("password","124");
%>
${username==‘aaa‘ && password==‘123‘ }
<br/>----------------empty运算符---------------------<br/>
<%
1、request.setAttribute("list",null);
2、request.setAttribute("list",new ArrayList());
%>
${empty(list) }
<br/>----------------二元运算符-------------------------<br/>
${user!=null ? user.username : ‘‘ }
<br/>----------------二元运算符(数据回显)-------------------------<br/>
<%
request.setAttribute("gender","male");
%>
<input type="radio" name="gender" value="male" ${gender==‘male‘?‘checked‘:‘‘ }>男
<input type="radio" name="gender" vlaue="female" ${gender==‘female‘?‘checked‘:‘‘ }>女
${pageContext} <!--为什么没有去域中取民为pageConetxt的值? -->
<br/>----------------使用el隐式对象访问指定的域-------------------------<br/>
<%
pageContext.setAttribute("aa","123");
%>
${aa} <!--这个是从四个域中查找 -->
${pageScope.aa} <!--从指点域中找 -->
${sessionScope.user!=null}
<br/>----------------获取保存了所有请求参数的Map对象----------------------<br/>
${param.name}
${paramValues.name[0]}
${paramValues.name[1]}
<br/>----------------获取请求头-------------------------<br/>
${header[‘Accept-Language‘] } <!--用[],用.不行,有个特殊符号 -->
<br/>---------------获取cookie-------------------------<br/>
${cookie.JSESSIONID.name }<br/>
${cookie.JSESSIONID.value }
${initParam.xx }
<%@taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
实例:
${fn:toLowerCase("AAAA") }
<%
request.setAttribute("arr",new String[5]);
%>
${fn:length(arr) }
<%
List list = new ArrayList();
list.add("aa");
list.add("bb");
request.setAttribute("list",list);
%>
<c:forEach var="i" begin="0" end="${fn:length(list)}">
${list[i] }
</c:forEach>
${fn:join(fn:split("www,itcast,cn",","),".") }
${fn:contains("aaaabbbcc","ab") }
${fn:escapeXml("<a href=‘‘>点点</a>")}
<br/>---------------取出用户填写的爱好回显------------------------<br/>
<%
request.setAttribute("likes",new String[]{"football","sing"});
%>
<input type="checkbox" name="likes" value="sing" ${fn:contains(fn:join(likes,","),"sing")?‘checked‘:‘‘ }>唱歌
<input type="checkbox" name="likes" value="dance" ${fn:contains(fn:join(likes,","),"dance")?‘checked‘:‘‘ }>跳舞
<input type="checkbox" name="likes" value="basketball" ${fn:contains(fn:join(likes,","),"basketball")?‘checked‘:‘‘ }>蓝球
<input type="checkbox" name="likes" value="football" ${fn:contains(fn:join(likes,","),"football")?‘checked‘:‘‘ }>足球
标签:
原文地址:http://www.cnblogs.com/wangweiNB/p/4992171.html