1 / * 2 * Demo Data Request object acquisition request line . 3 * / . 4 @WebServlet ( "/ Test" ) . 5 public class RequestDemo1 the extends the HttpServlet { . 6 protected void the doPost (the HttpServletRequest Request, the HttpServletResponse Response) throws ServletException, IOException { . 7 . 8 } . 9 10 protected void the doGet (the HttpServletRequest request, the HttpServletResponse Response) throws ServletException, IOException { . 11 // an acquisition request line 12 //1. Get request method: the GET 13 is String Method = request.getMethod (); 14 System.out.println (Method); 15 // 2 (*) Gets the virtual directory:. / Request 16 String the contextPath = request.getContextPath () ; . 17 System.out.println (the contextPath); 18 is // 3. Get Servlet path: / Demo . 19 String servletPath = request.getServletPath (); 20 is System.out.println (servletPath); 21 is // 4. Get get way request parameters: name = zhangshan 22 is String the queryString = request.getQueryString (); 23 is System.out.println(queryString); 24 //5.(*)获取请求URI:/request/demo 25 //* String getRequestURI(): /request/demo 26 String requestURI = request.getRequestURI(); 27 System.out.println(requestURI); 28 //* StringBuffer getRequestURI():http://localhost/request/demo 29 StringBuffer requestURL = request.getRequestURL(); 30 System.out.println(requestURL); 31 //6.获取协议及版本:HTTP/1.1 32 String protocol = request.getProtocol(); 33 System.out.println (Protocol); 34 is // 7. The acquired IP address of the client: 35 // * getRemoteAddr String () 36 String = remoteUser as request.getRemoteUser (); 37 [ System.out.println (remoteUser); 38 is } 39 }