request功能获取请求行数据

 1 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
 2         //获取请求方式
 3         String method=request.getMethod();
 4         System.out.println(method);
 5         //(*重要)获取虚拟路径
 6         String contextpath=request.getContextPath();
 7         System.out.println(contextpath);
 8         //获取Servlet路径
 9         String servletpath=request.getServletPath();
10         System.out.println(servletpath);
11         //获取参数
12         String querystring=request.getQueryString();
13         System.out.println(querystring);
14         //获取(*重要)URI/URL
15         String uri=request.getRequestURI();
16         StringBuffer url=request.getRequestURL();
17         System.out.println(uri);
18         System.out.println(url);
19         //获取协议
20         String protocol=request.getProtocol();
21         System.out.println(protocol);
22         //获取客户机的IP地址
23         String remoteadde=request.getRemoteAddr();
24         System.out.println(remoteadde);
25 
26     }

原文地址:https://www.cnblogs.com/hengzhezou/p/11108278.html