zoukankan      html  css  js  c++  java
  • 渚漪Day15——JavaWeb 06【HTTPServletRequest】

    4、HTTPServletRequest

    Servlet、用HTTPServletRequest接受并处理

    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");
        String username = req.getParameter("username");
        String password = req.getParameter("password");
        String[]hobbies = req.getParameterValues("hobbies");
    
        System.out.println(username+":"+password);
    
        System.out.println(Arrays.toString(hobbies));
    
        //resp.sendRedirect("success.jsp");
        req.getRequestDispatcher("success.jsp").forward(req, resp);
    }
    

    jsp、主页

    <%@ page contentType="text/html;charset=UTF-8" language="java" %>
    <html>
    <body>
    <h1>登录</h1>
    <div>
        <form action="${pageContext.request.contextPath}/login" method="post">
            用户名:<input type="text" name="username"><br>
            密&nbsp;&nbsp;&nbsp;码:<input type="password" name="password"><br>
            爱好:<input type="checkbox" name="hobbies" value="代码">代码
            <input type="checkbox" name="hobbies" value="vtb">vtb
            <input type="checkbox" name="hobbies" value="游戏">游戏
            <input type="checkbox" name="hobbies" value="音乐">音乐
            <input type="checkbox" name="hobbies" value="电影">电影
            <input type="checkbox" name="hobbies" value="运动">运动 <br>
            <input type="submit">
        </form>
    </div>
    </body>
    </html>
    

    jsp、成功

    <%@ page contentType="text/html;charset=UTF-8" language="java" %>
    <html>
    <head>
        <title>成功</title>
    </head>
    <body>
    <h1>登录成功</h1>
    </body>
    </html>
    

  • 相关阅读:
    linux 文件时间
    linux命令学习 touch
    linux命令学习 cp
    Linux命令学习 mv
    SpringMVC mvc详解
    JDBC原生态代码
    java中静态方法中调用非静态方法的详解
    Spring技术详解
    Spring中的 BeanFactory和 ApplicationContext的区别与解释
    java多线程编程相关技术
  • 原文地址:https://www.cnblogs.com/ijuysama/p/12785885.html
Copyright © 2011-2022 走看看