Request_获取请求行数据_方法介绍与Request_获取请求行数据_代码演示

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);


    }
}
复制代码

 

posted @   zj勇敢飞,xx永相随  阅读(29)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)
点击右上角即可分享
微信分享提示