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>
    

  • 相关阅读:
    字节输入输出流
    数据库安全性
    数据库设计:三种范式
    (Java篇) 代理服务:Nginx ---》(1)介绍及安装
    (十七)微信小程序:全局优化
    (十六)微信小程序:电影详情页
    (十五)微信小程序:优化电影页面
    (十四)微信小程序:上拉加载 下拉刷新
    (十三)微信小程序:更多电影页面
    管理:会议纲要
  • 原文地址:https://www.cnblogs.com/ijuysama/p/12785885.html
Copyright © 2011-2022 走看看