request对象的方法

时间:2019-09-09
本文章向大家介绍request对象的方法,主要包括request对象的方法使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

1、获取请求行信息

(1)get提交

 <body bgcolor="#f5f5dc">
  <center>
    <h3>登录</h3>
    <form action="http://localhost:8080/MyServlet_war_exploded/abc" method="get">
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;用户名:<input type="text" name="myname" size="12"><br>&nbsp;&nbsp;码:<input type="password" name="mypassword" size="6" ><br><br>
      <input type="reset" value="取消">
      <input type="submit" value="登录">
    </form>

  </center>
  </body>
 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        ServletOutputStream out=response.getOutputStream();
        String method= request.getMethod();
        System.out.println(method);
        String URI=request.getRequestURI();
        System.out.println(URI);
        StringBuffer URL=request.getRequestURL();
        System.out.println(URL);
        String path=request.getContextPath();
        System.out.println(path);
    }

 运行结果:

getMethod():获取提交方式
getRequestURI():URI
getRequestURL():URL

getContextPath():项目名称
(2)post提交

 2、获取请求头信息



原文地址:https://www.cnblogs.com/zhai1997/p/11489967.html