EL(Expression Language)
<%
User user=(User)session.getAttribute("user");
Dept dept=user.getDept();
String departname=dept.getDname();
%>
EL:
${sessionScope.user.dept.departname}
=${sessionScope.user.dept["departname"]} //.与[ ]意思一样,但[ ]内可以设置为变量,方便动态取值,而且对包含有“-”这些非字母与数字的符号,就必须用[ ],例如:${user["d-name"]}正确,${user.d-name}错误
EL变量有查询顺序:Page>Request>Session>Application,找不到回传null
JSP:EL:
page:pageScope;request:requestScope;session:sessionScope;application:applicationScope
JSP标准标签库JSTL(JSP standard tag library,Java EE 5.0标准的一部份)
使用必须在JSP页中导入标签库(核心库"/core" prefix="c" ,还有函数库 "/functions" prefix="fn")
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<c:forEach var="city" items="${cityList}"> //c:是前缀,forEach-循环迭代遍历集合,JSTL不在<% %>内
${city}<br/>
</c:forEach>
list个数:${fn:length(cityList)}
Core:
<c:out value=${city}>
<c:set target="${cityList}" property="cityname" value="guangzhou"> //给citylist的对象的cityname赋值"guangzhou"
${<fn:trim("AB C ")}D ="AB CD"