servlet补充
ServletContext
获取
context=getServletConfig().getServletContext();context=getServletContext()---genricServlet的方法
作用
- context上下文参数
username=context.getInitparamter("username")-----"admin"
context在web.xml配置如下
<context-param>
<param-name>username</param-name>
<param-value>admin</param-value>
</cintext-param>
- 工程路径: 格式 /路径
context.getContextPath()----"/servlet"
- 服务器硬盘绝对路径
context.getRealPath("/") //---斜杠被解析为http://ip:port/工程名/ //----结果:\IdeaProjects\Javawebloutlartifacts\06_servlet_war_exploded\
- 像map一样存取数据
context.setAttribute("key1","value1");
context.getAttribute("key1");
context.removeAttribute("key1");
MIME类型
超文本标记语言文本.html ,.htm text/html
普通文本.txt text/plain
GIF图形.gif image/gif
JpEG图形.jpeg..jpg image/jpeg
GZIOP文件 .gz application/x-gzip
HttpServletRequest类
request对象
getRequestURI() 获取请求的资源路径
getRequestURL()获取请求的统一资源定位符(绝对路径>
getRemoteHost()获取客户端的ip地址
getHeader()获取请求头
getParameter()获取请求的参数
getParameterValues()获取请求的参数(多个值的时候使用》
getMethod()获取请求的方式GET或POST
setAttribute( key , value);设置域数据
getAttribute(key );获取域数据
getRequestDispatcher() 获取请求转发对象
