1、與作用域范圍有關的四個隱式對象
pageScope、requestScope、sessionScope和applicationScope。?
它們可以讀取使用jsp內置對象pageContext、request、session以及application的setAttribute()方法所設定的對象的數值-----即getAttribute(Stringname),卻不能取得其他相關信息。?
? 例如,要取得session中儲存的一個username屬性的值,可以利用下面的方法:session.getAttribute("username")
在EL中則使用下面的方法:${sessionScope.username}
注意:如果沒有設定使用EL內置對象的作用范圍,則按照pageScope、requestScope、sessionScope和applicationScope的先后順序讀取屬性值。
即,通知JSP引擎調用pageContext.findAttribute()方法,以標識符為關鍵字從各個域對象中獲取對象。如果域對象中不存在標識符所對應的對象,則返回結果為“”(注意,不是null)。
2、?與輸入有關的兩個隱式對象
param和?paramValue。主要用于取得請求參數。
? request.getParameter(Stringname)
request.getParameterValues(String name)
在EL中則可以使用param和paramValues兩者來取得數據:
${param.name}*****${paramValues.name}
3、cookie
用來取得使用者的cookie值,例如在cookie中設定了username屬性值,可以使用${cookie.username.value}?
4、header和headerValues
?讀取請求的頭數據,使用header或headerValues內置對象,例如${header[“User-Agent”]},headerValues則用來取得所有的頭信息,等價于調用request.getHeaders()方法。
5、initParam
?initParam用來讀取設置在web.xml中的參數值。例如${initParam.repeat},
等價于:(String)application.getInitParameter(“repeat”);
或:servletContext.getInitParameter(“repeat”);
6、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.1、HTTP/1.0)
${pageContext.request.remoteUser} 取得用戶名稱
${pageContext.request.remoteAddr} 取得用戶的ip 地址
${pageContext.session.new} 判斷session 是否為新的
${pageContext.session.id} 取得session 的ID
${pageContext.servletContext.serverInfo} 取得主機端的服務信息
?查看JSP九個隱式對象點擊打開鏈接(http://blog.csdn.net/j080624/article/details/52965366)
新聞熱點
疑難解答