四大對象
HttpServletRequest 請求對象:獲取請求信息
HttpServletResponse 響應(yīng)對象: 設(shè)置響應(yīng)對象
ServletConfig對象 servlet配置對象
ServletContext對象羡玛; servlet的上下文對象
ServletConfig的API:
String getInitParameter(String name) 根據(jù)參數(shù)名獲取參數(shù)值
Enumeration getInitParameterNames() 獲取所有參數(shù)
ServletContext getServletContext() 得到servlet上下文對象
String getServletName() 得到servlet的名稱
注意:servlet的參數(shù)只能由當(dāng)前的這個(gè)sevlet獲取F北搿!(名字要對)
ServletContext對象的核心API
String getContextPath() --得到當(dāng)前web應(yīng)用的路,用在請求重定向的資源名稱中
String getInitParameter(String name) --得到web應(yīng)用的初始化參數(shù)
Enumeration getInitParameterNames()
注意:web應(yīng)用參數(shù)可以讓當(dāng)前web應(yīng)用的所有servlet獲壤Φ取!续室!
void setAttribute(String name,Object object) --域?qū)ο笥嘘P(guān)的方法
Object getAttribute(String name)
void removeAttribute(String name)
RequestDispatcher getRequestDispatcher(java.lang.String path) --轉(zhuǎn)發(fā)(類似于重定向)
String getRealPath(String path) --得到web應(yīng)用的資源文件
InputStream getResourceAsStream(String path)
對象創(chuàng)建和得到
創(chuàng)建時(shí)機(jī):加載web應(yīng)用時(shí)創(chuàng)建ServletContext對象栋烤。
得到對象: 從ServletConfig對象的getServletContext方法得到
域?qū)ο?/h2>
作用:用于保存數(shù)據(jù),獲取數(shù)據(jù)挺狰∶鞴可以在不同的動態(tài)資源之間共享數(shù)據(jù)。
ServletContext就是一個(gè)域?qū)ο螅丰泊。?/p>
- 保存數(shù)據(jù):setAttribute(jString name, Object object)
- 取出數(shù)據(jù):getAttribute(String name)
- 刪除數(shù)據(jù): removeAttribute(String name)