2020-12-16
阿新 • • 發佈:2020-12-17
目錄
JSP 的9大內建物件
- pageContext JSP頁面容器
- request 請求物件
- response 響應對話
- session 會話物件
- appliation 全域性物件
- config 配置物件(服務期配置資訊)
- out 輸出物件
- page 當前JSP頁面物件(相當於Java中的this)
- exception 異常物件
- Cookie 不是內建物件!!!!!!!!用的時候需要new
一、appliation 全域性物件
4中共有屬性
- void setAttribute(String name,Object obj) 設定屬性值(新增、修改)
<% pageContext.setAttribute("first","Hello World!!"); //新增一個名為first,值為Hello World!! %> <%=pageContext.getAttribute("first")+"<br/>" %> <% pageContext.setAttribute("first", "My name is JavaWeb.jsp"); //修改名為first的屬性改其值為My name is JavaWeb.jsp %> <%=pageContext.getAttribute("first")+"<br/>" %>
- Object getAttribute(String name) 根據屬性名獲取屬性值
- void removeAttribute(String name) : 根據屬性名刪除物件
- String getContextPath() 獲取虛擬路徑
-
<%= "虛擬路徑是: "+ application.getContextPath() %>
- String getRealPath( String name) 獲取絕對路徑
-
<%= "虛擬路徑對應的絕對路徑: "+ application.getRealPath( "/MyJspProject")%>
-
二、request 請求物件
同一次請求有效!!
-
三、session 會話物件