1.通过request获得请求行
获得客户端的请求方式:String
getMethod()
获得请求的资源:
String
getRequestURI()
StringBuffer
getRequestURL()
String
getContextPath()
---web
应用的名称
String
getQueryString()
---- get
提交
url
地址后的参数字符串
username=zhangsan&password=123
注意:request获得客户机(客户端)的一些信息
request.getRemoteAddr() --- 获得访问的客户端IP地址
2.通过request获得请求头
long
getDateHeader(
String name)
Enumeration
getHeaderNames()
Enumeration
getHeaders(
String name)
int
getIntHeader(
String name)
referer头的作用:执行该此访问的的来源
做防盗链
3.通过request获得请求体
请求体中的内容是通过post提交的请求参数,格式是:
username=zhangsan&password=123&hobby=football&hobby=basketball
key ---------------------- value
username [zhangsan]
password [123]
hobby [football,basketball]
以上面参数为例,通过一下方法获得请求参数:
String
getParameter(
String name)
String[]
getParameterValues(
String name)
Enumeration
getParameterNames()
Map<String,String[]>
getParameterMap()
注意:get请求方式的请求参数 上述的方法一样可以获得
解决post提交方式的乱码:request.setCharacterEncoding("UTF-8");
解决get提交的方式的乱码:
parameter = new String(parameter.getbytes("iso8859-1"),"utf-8");