ServletContext对象详解
生活随笔
收集整理的這篇文章主要介紹了
ServletContext对象详解
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
ServletContext對象
1. 概念:代表整個web應用,可以和程序的容器(服務器)來通信
2. 獲取:
?? ?1. 通過request對象獲取
?? ??? ?request.getServletContext();
?? ?2. 通過HttpServlet獲取
?? ??? ?this.getServletContext();
3. 功能:
?? ?1. 獲取MIME類型:
?? ??? ?* MIME類型:在互聯網通信過程中定義的一種文件數據類型
?? ??? ??? ?* 格式: 大類型/小類型 ? text/html?? ??? ?image/jpeg
?? ??? ?* 獲取:String getMimeType(String file) ?
??
?2. 域對象:共享數據
?? ??? ?1. setAttribute(String name,Object value)
?? ??? ?2. getAttribute(String name)
?? ??? ?3. removeAttribute(String name)
?? ??? ?ServletContext對象范圍:所有用戶所有請求的數據
? ?
3. 獲取文件的真實(服務器)路徑
?? ??? ?1. 方法:String getRealPath(String path) ?
? ? ? ? ? ?
總結
以上是生活随笔為你收集整理的ServletContext对象详解的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 验证码的编写——本质:图片目的:防止恶意
- 下一篇: 会话技术 —— Cookie 实现原理