文档库 最新最全的文档下载
当前位置:文档库 › EL表达式和JSTL

EL表达式和JSTL

El表达式和jstl的基础[原创][i=s] 本帖最后由 SkySeven 于 2009-6-14 12:36 编辑 [/i]

El表达式
1.EL表达式需要的环境:servlet2.4/jsp2.0

2.EL表达式的运算符 . []
${https://www.wendangku.net/doc/1b8047383.html,} 等价于 ${https://www.wendangku.net/doc/1b8047383.html,er[“name”]}
注意:如果你的你存放的在key值有特殊的字符则必须是用”[]”的运算符,像出现这个的字符“-,@”等等 如:${https://www.wendangku.net/doc/1b8047383.html,er[“user_name”]};

3.EL表达式的隐含对象 与jsp中对应
1.输入有关的隐含对象
param = request.getParameter(“”);
paramValues = request.getParameterValues(“”);
注:paramValues 返回的是一个数组 对表单提交的有多个的选则的时候使用到的
2.与范围有关的隐含对象

pageScope = page.getAttribute(“”);
requestScope = request.getAttribute(“”);
sessionScope = session.getAttribute(“”);
applicationScope = servletContext.getAttribute(“”);

重点掌握一个 pageContext
pageContext可以用来获取其他的内置对象
向我们很熟悉的${pageContext.request.contextPath}
= <%=request.getContextPath()%>
用pageContext获取sessionId
${pageContext.session.id}
cookie = request.getCookies();

其他的:
header
headerValues
initParam 这个是用来获取web.xml中的配置文件

userid
mike

在servlet相当与 ServletConfig config = this.getServletConfig();
config.getInitParameter(“userid”);的是一个配置文件的值

对map取值:通过 map.key 是键 map.value 是值

上面都是以map的形式放在缓存中的

在el表达式运算符
and or ge/>= gt/> le/<= lt/<
mod/% div/”/” ne /!= eq/=
false true empty instanceof

jstl的核心标签库

<%@ taglib uri=”[url]https://www.wendangku.net/doc/1b8047383.html,/jsp/jstl/core[/url]” prefix=”c”%>
1.的用法


2.


3.



4.
在jsp中是用来移除变量

=


5:在jstl中表示 if.........else if...............else的条件

el表达式”>




当上面的条件都不满足的时候将要执行的代码




重点:
6: = for循环

解说: items:将被遍历的集合 (Collection/Map/Arrays)
begin:开始的位置
end:结束的位子
var:放在缓存中的键
step;是步长 默认为1
varStatus:一般可以用控制表格的隔行显示的颜色
index:当前成员的索引值
count:共访问成员的数量
first:当前成为是否为第一个成员
last: 当前成员是否为最后一个成员


varStatus的使用实例:

${n}  



通过varStatus中的属性来控制样式的显示方式









index: ${status.index}

count: ${status.count}

first: ${status.first}

last: ${https://www.wendangku.net/doc/1b8047383.html,st}

${e}


7.用于jsp中对一个字符窜的遍历

delims是用来按照什么格式来分割string = string 中split(“”);

实例:
String str = “chen:xue:lin”;

${test}


jstl自定义标签库


<%taglib uri=”[url]https://www.wendangku.net/doc/1b8047383.html,/jsp/jstl/ftm[/url]” prefix=”ftm”%>

值”
var=””
scope=”page/request/session/appliaction”
type=”number/currency货币/percent百分比”
currencyCode=”currencyCode” 标准的货币字符 cny(人民币) usd 美元
currencySymbol=”currencySymbol” 标准的货币符号:¥ $
groupingUsed=”true/false” 是否对数值区隔
maxFractionDigits=””多少位小数
maxIntegerDigits=””多少位整数
pattern=””格式化数值如:###,###.##
>

注意在当当网中我们还用了一个标签库:
<%@ taglib prefix=”fn” uri=”[url]https://www.wendangku.net/doc/1b8047383.html,/jsp/jstl/functions[/url]”%>
${fn:contains(string,substring)} 在string字符窜中是否包含substring字符窜
${fn:containsIgnoreCase(string,substring)}
${fn:startsWith(string,suffixstring)}
${fn:endWith(string,suffixstring)}
${fn:escapeXml(string)}将字符窜string 进行特殊转换
${fn:indexOf(string,substring)}
${fn:split(string,”,”)}
${fn:join(array,sepatator)}//合并字符窜
${fn:replace(string,oldstring,newstring)}
${fn:trim(string)}
${fn:substring(string,beginIndex,endIndex)}
${fn:substringAfter(string,substring)}
${fn:toLowerCase(string)}
${fn:toUpperCase(string)}
${fn:length(input)} 取得集合对象的数量或者字符窜中的字符数

相关文档