首页 > Web开发 > 详细

servlet HttpServletRequest 类 2 获取请求参数

时间:2020-03-28 10:09:09      阅读:54      评论:0      收藏:0      [点我收藏+]

如何获取请求参数

<body>
  <form action="http://localhost:8080/07_servlet/parameterServlet" method="get">
    用户名:<input type="text" name="username"><br/>
    密码:<input type="password" name="password"><br/>
    兴趣爱好:<input type="checkbox" name="hobby" value="cpp">C++
    <input type="checkbox" name="hobby" value="java">Java
    <input type="checkbox" name="hobby" value="js">JavaScript<br/>
    <input type="submit">
  </form>
</body>
protected void doGet(HttpServletRequest req, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        // 获取请求参数
        String username = req.getParameter("username");
        String password = req.getParameter("password");
        String[] hobby = req.getParameterValues("hobby");
        System.out.println("用户名:" + username);
        System.out.println("密码:" + password);
        System.out.println("兴趣爱好:" + Arrays.asList(hobby));
    }

servlet HttpServletRequest 类 2 获取请求参数

原文:https://www.cnblogs.com/superxuezhazha/p/12585794.html

(1)
(1)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!