1. 程式人生 > >EL表示式基礎

EL表示式基礎

<%@ page language="java" pageEncoding="utf-8" import="com.study.vo.*,java.util.*" %>
<html>
    <head>
    
    </head>
    <body>
        <h2>使用普通方法獲得作用域物件</h2>
        <b><%=request.getParameter("name")%></b><br/>
        <b><%
=request.getAttribute("str")%></b><br/> <b><%=((User)request.getAttribute("user")).getAddress().getAddr() %></b><br/> <b><%=((ArrayList<User>)request.getAttribute("list")).get(0).getAddress().getAddr() %></b><br/> <
b><%=((HashMap<String,User>)request.getAttribute("map")).get("user").getAddress().getAddr()%></b> <hr/> <h2>使用EL表達示獲得作用域物件(優點:不用導包,閱讀方法,程式碼更少)</h2> <b>${param.name}</b><br/> <b>${str}</b><br/> <
b>${user.address.addr}</b><br/> <b>${list[0].address.addr}</b><br/> <b>${map.user.address.addr}</b><br/> <h2>EL表示式獲取物件預設順序</h2> <% pageContext.setAttribute("hello","pagecontext"); request.setAttribute("hello","request"); session.setAttribute("hello","session"); application.setAttribute("hello","application"); %> <b>pageContext-->request-->session-->application</b><br> <b>${pageScope.hello}</b><br> <b>${requestScope.hello}</b><br> <b>${sessionScope.hello}</b><br> <b>${applicationScope.hello}</b><br> <h2>EL表示式的算術運算</h2> <strong>不支援字串連線</strong><br/> ${1+2}--${1-2}--${1>2}--${1==2?0:0}--${1+"2"} </body> </html>