jsp學習筆記4

Building JSP using the Expression Language

EL的基本語法與運算子   ${ EL表示式 }

El隱含對象

隱含對象名稱è用途(等同於何方法)è範例

pageScopeèpage範圍取得某屬性è${pageScope.title}

requestScopeèrequest範圍取得某屬性è${requestScope.title}

sessionScopeèsession範圍取得某屬性è${sessionScope.loginName}

applicationScopeèapplication範圍取得某屬性è${applicationScope.profile}

pageContextè包含JSP網頁信息的pageContext對象è${pageContext.request.requestURI}

paramèServletRequest.getParameter()方法è${param.productlId}

paramValuesèServletRequest.getParameterValues()方法è${paramValues.categories[0]}  (數組)

headerèServlet.Request.getHeader()方法è${header[“User-Agent”]}

headerValuesèServlet.Request.getHeaders()方法è${headerValues[“Accept-Encoding”][0]}

cookieèServletRequest.getCookies()方法è${cookie.username}

initParamèServletContext.getInitParameter()方法è${initParam.logDirectory}

 

注意:只有pageContext的類型爲java.servlet.ServletContext,其它隱含物件類型均爲java.util.Map

如果未指定範圍,JSP容器會依序從page,request,sessionapplication範圍尋找該屬性。(由小至大範圍尋找)

 

注意:使用EL除法運算時,如果除數爲0(例如10 div 0),結果會傳回Infinity(無限大)

EL算術運算子: + , - , * , / div , % mod

EL比較運算子:< lt , > gt , <= le , >= ge , == eq , != ne

EL ?號表達式:${邏輯表達式?1:2}

EL通過編寫一個類,把方法設置爲public,static,進行tld設置,可以實現靜態功能。

.(dot)的左邊可以爲隱含對象或者attribte。[]左邊可以爲,bean,map,list或者數組。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章