一、基本語法:${表達式}(至關於<%= 表達式 %>java
二、例:訪問域名爲key的請求參數:web
java代碼:<%=request.getParameter("key") %> EL表達式:${param.key} cookie
param是EL的內置對象,用於獲取請求參數的值。
session
三、EL的內置對象:app
與做用範圍有關的EL隱含對象包含有:pageScope、requestScope、sessionScope和applicationScope,它們能夠讀取使用JSP內置對象pageContext、request、session以及application的setAttribute()方法所設定的對象的數值-----即getAttribute(String name),卻不能取得其餘相關信息。 例如,要取得session中儲存的一個username屬性的值,能夠利用下面的方法:session.getAttribute("username"), 在EL中則使用下面的方法:${sessionScope.username}ide
注意:若是沒有設定使用EL內置對象的做用範圍,則按照pageScope、requestScope、sessionScope和applicationScope的前後順序讀取屬性值。即,通知JSP引擎調用pageContext.findAttribute()方法,以標識符爲關鍵字從各個域對象中獲取對象。若是域對象中不存在標識符所對應的對象,則返回結果爲「」(注意,不是null)。spa
與輸入有關的隱含對象有兩個,即param和paramValues,它們是EL中比較特別的隱含對象。例如,要取得用戶的請求參數時,能夠利用下列方法:orm
request.getParameter(String name), request.getParameterValues(String name)server
在EL中則能夠使用param和paramValues二者來取得數據:xml
${param.name} ${paramValues.name
cookie:用來取得使用者的cookie值,例如在cookie中設定了username屬性值,能夠使用${cookie.username.value}來取得屬性值。
header和headerValues: 讀取請求的頭數據,使用header或headerValues內置對象,例如${header[「User-Agent」]},headerValues則用來取得全部的頭信息,等價於調用request.getHeaders()方法。
initParam:initParam用來讀取設置在web.xml中的參數值。例如${initParam.repeat},等價於:(String)application.getInitParameter(「repeat」); 或servletContext.getInitParameter(「repeat」);
pageContext: pageContext用於取得其餘有關用戶要求或頁面的詳細信息
${pageContext.request.queryString} 取得請求的參數字符串
${pageContext.request.requestURL} 取得請求的URL,不包括參數字符串
${pageContext.request.contextPath} 服務的web application 的名稱
${pageContext.request.method} 取得HTTP 的方法(GET、POST)
${pageContext.request.protocol} 取得使用的協議(HTTP/1.一、HTTP/1.0)
${pageContext.request.remoteUser} 取得用戶名稱
${pageContext.request.remoteAddr } 取得用戶的IP 地址
${pageContext.session.new} 判斷session 是否爲新的
${pageContext.session.id} 取得session 的ID
${pageContext.servletContext.serverInfo} 取得主機端的服務信息