標籤:express length cat efi val stand for user string
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"
Java學習06 (第一遍) - JSP與Servlet