記錄四個隱含物件 :

pageScope:  相當於pageContext

requestScope:  相當於request

sessionScope:   相當於session

applicationScope: 相當於application

 

pageScope:  變數只能在本頁面使用。

requestScope:變數能在本次請求中使用。

Ex: request.setAttribute("error", "名稱或密碼錯誤");  //設定了error的資訊後

利用${ requestScope.error }來取

也等於request.getAttribute("error")

 

 

sessionScope:(應該是變數能在session期效內使用)。

Ex:  request.getSession().setAttribute("login", user); // 設定了login 的資訊

利用${sessionScope.login}來取

也等於 session.getAttribute("login")

 

applicationScope:變數能在整個應用程序中使用。

 

&(param.user)  = <%= request.getParameter("user") %>

paramValues = request.getParameterValues()

cookie 也可使用 ${cookie.userage}

 

初始參數可以用web.xml來設定  

Ex:

${initParam.initCount}  = <%= servletContext.getInitParameter("initCount") %>

 

 自定EL函式:

 

${ util:length(requestScope.someList) }

Util.java:

public class Util {
public static int length(Collection collection) {
return collection.size();
}
}

(此例子來自Servlet & Jsp使用手冊(第二版))

 

 

 

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 JoshS 的頭像
    JoshS

    JoshS的部落格

    JoshS 發表在 痞客邦 留言(0) 人氣()