Request_获取请求行数据_方法介绍
request功能:
1.获取请求消息数据
1.获取请求行数据
GET/day14/demo1?name = zhangsan HTTP/1.1
方法:
1.获取请求方式:GET
String getMethod()
2.获取虚拟目录:/day14
String getContexpath
3.获取Servlet路径:/demo1
String getServlet
4.获取get方式请求参数:name=zhangsan
String getQueryString()
5.获取请求URI:/day14/demo1
String getRequestURL() :http://localhost/day14/demo1
StringBuffer getRequestURl
URL:统一资源定位符 :http://localhost/day14/demo1
URI:统一资源标识符 :/day14/demo1
6.获取协议及版本:HTTP/1.1
String getProtocol()
7.获取客户端的IP地址:
String getRemoteAddr()
2.获取请求头数据
3.获取请求提数据
2.其他功能
Request_获取请求行数据_代码演示
package jinghai.xueqiang.web.request; import jakarta.servlet.*; import jakarta.servlet.http.*; import jakarta.servlet.annotation.*; import java.io.IOException; @WebServlet(name = "requestDemo1", value = "/requestDemo1") public class RequestDemo1 extends HttpServlet { @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { } @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { /* 1.获取请求方式:GET String getMethod() 2.获取虚拟目录:/day14 String getContexpath 3.获取Servlet路径:/demo1 String getServletPath 4.获取get方式请求参数:name=zhangsan String getQueryString() 5.获取请求URI:/day14/demo1 String getRequestURL() :http://localhost/day14/demo1 StringBuffer getRequestURl 6.获取协议及版本:HTTP/1.1 String getProtocol() 7.获取客户端的IP地址: String getRemoteAddr() */ //1.获取请求方式:GET String s1 = request.getMethod(); System.out.println(s1); // 2.获取虚拟目录:/day14 String s2 = request.getContextPath(); System.out.println(s2); //3.获取Servlet路径:/demo1 String s3 = request.getServletPath(); System.out.println(s3); //4.获取get方式请求参数:name=zhangsan String s4 = request.getQueryString(); System.out.println(s4); //5.获取请求URI:/day14/demo1 String s5 = request.getRequestURI(); System.out.println(s5); StringBuffer S5s = request.getRequestURL(); System.out.println(S5s); //6.获取协议及版本:HTTP/1.1 String s6 = request.getProtocol(); System.out.println(s6); //7.获取客户端的IP地址: String s7 = request.getRemoteAddr(); System.out.println(s7); } }
标签:请求,Request,request,day14,获取,demo1,String From: https://www.cnblogs.com/x3449/p/17073183.html