YuFeng

Request 响应
获取访问的地址 request.getRemoteAddr() 获取请求头里的内容,例如获取请求网页的UA req...
扫描右侧二维码阅读全文
20
2019/06

Request 响应

获取访问的地址
request.getRemoteAddr()
获取请求头里的内容,例如获取请求网页的UA
request.getHeader("User-Agent")
获取请求头里的所有内容
Enumeration<String> headerNames = request.getHeaderNames();
while(headerNames.hasMoreElements()) {
String nextElement = headerNames.nextElement();
System.out.println(request.getHeader(nextElement));
}
获得所访问的web程序/web15
System.out.println(request.getContextPath());
获得访问的地址http://192.168.3.2/web15/servler
System.out.println(request.getRequestURL());
获得请求表单里面的内容<将所有的表单封装成一个Map集合中,键值对应>
Map<String, String[]> parameterMap = request.getParameterMap();
生成一个随机数UID   32位数值
UUID.randomUUID().toString()


request获得行的内容
      request.getMethod()
      request.getRequestURI()
      request.getRequestURL()
      request.getContextPath()
      request.getRemoteAddr()
request获得头的内容
      request.getHeader(name)
request获得体(请求参数)
      String request.getParameter(name)
      Map<String,String[]> request.getParameterMap();
      String[] request.getParameterValues(name);
      注意:客户端发送的参数 到服务器端都是字符串
 
      获得中文乱码的解决:
         post:request.setCharacterEncoding(“UTF-8”);
         get:
parameter = new String(parameter.getBytes(“iso8859-1”),”UTF-8”);
 
request转发和域
      request.getRequestDispatcher(转发的地址).forward(req,resp);
      request.setAttribute(name,value)
      request.getAttribute(name)
Last modification:June 20th, 2019 at 10:28 am
If you think my article is useful to you, please feel free to appreciate

Leave a Comment