<%
String pageValue = "Hello This is page";
pageContext.setAttribute("pageV", pageValue);
request.setAttribute("reqValue",
"<font color='red'>Hello Request</font>");
session.setAttribute("sessionValue",
"<font color='green'>Hello session</font>");
application.setAttribute("appValue",
"<font color='blue'>Hello Application</font>");
%>
<!-- EL/JSTL复习总结 -->
<h1>1.JSP脚本:</h1>
<div>
JSP表达式:<%=pageContext.getAttribute("pageV")%><br />
JSP表达式:<%=request.getAttribute("reqValue")%><br />
JSP表达式:<%=session.getAttribute("sessionValue")%><br />
JSP表达式:<%=application.getAttribute("appValue")%><br />
</div>
<h1>2.EL表达式:</h1>
<div>
EL表达式:${pageV }<br/>
EL表达式:${reqValue }<br/>
EL表达式:${sessionValue }<br/>
EL表达式:${appValue }<br/>
【查找顺序:pageScope-requestScope-sessionScope-applicationScope】
</div>
<h1>3.EL表达式+scope:</h1>
<div>
EL表达式:【pageScope】:${pageScope.pageV }<br/>
EL表达式:【requestScope】:${requestScope.reqValue }<br/>
EL表达式:【sessionScope】:${sessionScope.sessionValue }<br/>
EL表达式:【applicationScope】:${applicationScope.appValue }<br/>
</div>
<h1>4.JSTL表达式:</h1>
<div>
JSTL表达式:this【pageScope】:<c:out value="${pageScope.pageV }" /><br/>
JSTL表达式:request:【requestScope】【escapeXml="false"】<c:out value="${requestScope.reqValue }" escapeXml="false"/><br/>
JSTL表达式:session:【sessionScope】<c:out value="${sessionScope.sessionValue }" /><br/>
JSTL表达式:application:【applicationScope】<c:out value="${applicationScope.appValue }" /><br/>
JSTL表达式:page:<c:out value="${applicationScope.appValue }" /><br/>
JSTL表达式:noThisValue【default="ErrorEmpty"】:<c:out value="${noThisValue }" default="<font size='+3'>ErrorEmpty</font>" escapeXml="false"/><br/>
</div>
输出:
JSP脚本:
JSP表达式:Hello This is page
JSP表达式: Hello Request
JSP表达式: Hello session
JSP表达式: Hello Application
JSP表达式: Hello Request
JSP表达式: Hello session
JSP表达式: Hello Application
EL表达式:
EL表达式:Hello This is page
EL表达式: Hello Request
EL表达式: Hello session
EL表达式: Hello Application
【查找顺序:pageScope-requestScope-sessionScope-applicationScope】
EL表达式: Hello Request
EL表达式: Hello session
EL表达式: Hello Application
【查找顺序:pageScope-requestScope-sessionScope-applicationScope】
EL表达式:
EL表达式:【pageScope】:Hello This is page
EL表达式:【requestScope】: Hello Request
EL表达式:【sessionScope】: Hello session
EL表达式:【applicationScope】: Hello Application
EL表达式:【requestScope】: Hello Request
EL表达式:【sessionScope】: Hello session
EL表达式:【applicationScope】: Hello Application
JSTL表达式:
JSTL表达式:this【pageScope】:Hello This is page
JSTL表达式:request:【requestScope】【escapeXml="false"】 Hello Request
JSTL表达式:session:【sessionScope】<font color='green'>Hello session</font>
JSTL表达式:application:【applicationScope】<font color='blue'>Hello Application</font>
JSTL表达式:page:<font color='blue'>Hello Application</font>
JSTL表达式:noThisValue【default="ErrorEmpty"】: ErrorEmpty
JSTL表达式:request:【requestScope】【escapeXml="false"】 Hello Request
JSTL表达式:session:【sessionScope】<font color='green'>Hello session</font>
JSTL表达式:application:【applicationScope】<font color='blue'>Hello Application</font>
JSTL表达式:page:<font color='blue'>Hello Application</font>
JSTL表达式:noThisValue【default="ErrorEmpty"】: ErrorEmpty
[要点]
1.EL表达式的作用域
2.JSTL
<c:out value="">的default、escapeXml属性
***********************
EL表达式:
名字:${user.username }
性别:<c:if test="${user.gender != \"F\"}">男</c:if>
所在系:${user.dept.dname }
访问map:[
map名.keyx
]:${user.dept.map.k1}
访问array[index]:${user.dept.arrays[0]}
访问list[index]:${user.dept.list[0]}