Request_获取请求行数据_方法介绍:
request功能:
获取请求消息
获取请求行数据
GET /demo3?name=zhangsan HTTP/1.1
方法:
1.获取请求方式:GET
String getMethod();
2.(*)获取虚拟目录:/day14
String getContextPath();
3.获取Serevlet路径:/demo1
String getServletPath()
4.获取get方式请求参数:name=zhangsan
String getQueryString()
5.(*)获取请求URI:/day14/demo1
String getRequestURI():/day14/demo1 共和国
StringBuffer getRequestURL():http://localhost/day14/demo1 中华人民共和国
URL:统一资源定位符
URI:统一资源标识符
6.获取协议及版本:HTTP/1.1
String getProtocol()
7.获取客户机的IP地址:
String getRemotAddr()
Request_获取请求行数据_代码演示:
@WebServlet(name = "RequestDemo1", value = "/RequestDemo1") public class RequestDemo1 extends HttpServlet { @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { /* 1.获取请求方式:GET String getMethod(); 2.(*)获取虚拟目录:/day14 String getContextPath(); 3.获取Serevlet路径:/demo1 String getServletPath() 4.获取get方式请求参数:name=zhangsan String getQueryString() 5.获取请求URI:/day14/demo1 String getRequestURI():/day14/demo1 StringBuffer getRequestURL():http://localhost/day14/demo1 6.获取协议及版本:HTTP/1.1 String getProtocol() 7.获取客户机的IP地址: String getRemotAddr() */ //1.获取请求方式:GEI String method = request.getMethod(); System.out.println(method); //2.(*)获取虚拟目录:/day14 String contextPath = request.getContextPath(); System.out.println(contextPath); //3.获取Serevlet路径:/demo1 String servletPath = request.getServletPath(); System.out.println(servletPath); //4.获取get方式请求参数:name=zhangsan String queryString = request.getQueryString(); System.out.println(queryString); //5.获取请求URI:/day14/demo1 String requestURI = request.getRequestURI(); System.out.println(requestURI); StringBuffer requestURL = request.getRequestURL(); System.out.println(requestURL); //6.获取协议及版本:HTTP/1.1 String protocol = request.getProtocol(); System.out.println(protocol); //7.获取客户机的IP地址: String remoteAddr = request.getRemoteAddr(); System.out.println(remoteAddr); } @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { }
标签:请求,Request,request,day14,获取,demo1,String From: https://www.cnblogs.com/hungui/p/16967267.html