servlet HttpServletRequest 类 2 获取请求参数

如何获取请求参数

<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));
    }
posted @ 2020-03-28 09:40  超级学渣渣  阅读(...)  评论(...编辑  收藏