zoukankan      html  css  js  c++  java
  • Servlet学习-request

    public void doGet(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException {
    
            response.setContentType("text/html;charset=utf-8");
            PrintWriter out = response.getWriter();
            
            //获取url
            String url = request.getRequestURL().toString();
            //获取uri
            String uri = request.getRequestURI();
            //QueryString获取?后面的参数和值
            String qs =request.getQueryString();
            //IP地址
            String ip = request.getRemoteAddr();
            //主机名
            String host  = request.getRemoteHost();
            //网络端口号
            int port = request.getRemotePort();
            int localport = request.getLocalPort();
            //拆分内容
            String[] substr = qs.split("&");
            for(String s:substr)
            {
            //    out.println(Mytools.GetString(s)+"<br>");
                String ss[] = s.split("=");
                out.println(ss[0]+"转前= "+ss[1]+"<br>");
                out.println(ss[0]+"转后= "+Mytools.GetString(ss[1])+"<br>");
            }
            
            
            
            out.println("localport= "+localport+"<br>");
            out.println("IP= "+ip+"<br>");
            out.println("host= "+host+"<br>");
            out.println("qs= "+qs+"<br>");
            out.println("url= "+url+"<br>");
            out.println("uri= "+uri+"<br>");
            out.println("port= "+port+"<br><br>");
            
            
            //getHeaderNames 获取HTTP请求所有的消息头
            Enumeration<String> hn= request.getHeaderNames();
            while(hn.hasMoreElements())
            {
                String headname = hn.nextElement();
                out.println(headname+":    "+request.getParameter(headname)+"<br>");
            }
        }

    request用于获取http请求的信息

  • 相关阅读:
    MySQL 子查询
    MySQL 多表查询 内连接 和 外连接
    MySQL 分页
    MySQL 常用函数 流程控制
    Envoy基于文件系统的EDS动态配置
    Envoy学习笔记
    dapr入门学习
    浅谈cache
    List的初始化方式
    屌丝公司:设置服务器的时区、时间及时间同步
  • 原文地址:https://www.cnblogs.com/bersaty/p/3202558.html
Copyright © 2011-2022 走看看