ServletContext对象详解
ServletContext對象
1. 概念:代表整個(gè)web應(yīng)用,可以和程序的容器(服務(wù)器)來通信
2. 獲取:
?? ?1. 通過request對象獲取
?? ??? ?request.getServletContext();
?? ?2. 通過HttpServlet獲取
?? ??? ?this.getServletContext();
3. 功能:
?? ?1. 獲取MIME類型:
?? ??? ?* MIME類型:在互聯(lián)網(wǎng)通信過程中定義的一種文件數(shù)據(jù)類型
?? ??? ??? ?* 格式: 大類型/小類型 ? text/html?? ??? ?image/jpeg
?? ??? ?* 獲取:String getMimeType(String file) ?
??
?2. 域?qū)ο?#xff1a;共享數(shù)據(jù)
?? ??? ?1. setAttribute(String name,Object value)
?? ??? ?2. getAttribute(String name)
?? ??? ?3. removeAttribute(String name)
?? ??? ?ServletContext對象范圍:所有用戶所有請求的數(shù)據(jù)
? ?
3. 獲取文件的真實(shí)(服務(wù)器)路徑
?? ??? ?1. 方法:String getRealPath(String path) ?
? ? ? ? ? ?
總結(jié)
以上是生活随笔為你收集整理的ServletContext对象详解的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 验证码的编写——本质:图片目的:防止恶意
- 下一篇: 会话技术 —— Cookie 实现原理