Request应用

前端的页面

<html>
<head>
    <title>Title</title>
</head>
<body>
<h1>登陆</h1>

<div style="text-align: center">
    <form action="/login" method="post">
        用户名:<input type="text" name="username"> <br>
        密码:<input type="password" name="password"> <br>
        爱好:
        <input type="checkbox" name="hobbys" vaule="女孩">女孩
        <input type="checkbox" name="hobbys" vaule="代码">代码
        <input type="checkbox" name="hobbys" vaule="唱歌">唱歌
        <input type="checkbox" name="hobbys" vaule="电影">电影
        <input type="checkbox" name="hobbys" vaule="蜡笔小新">蜡笔小新

        <br>
        <input type="submit">
    </form>
</div>>


</body>
</html>

前端为post的提交方式,后台也要用post方法

 @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        //得到参数username的内容
        String username = req.getParameter("username");
        //得到password的参数
        String password = req.getParameter("password");
        //得到hobbys的参数
        String[] hobbys = req.getParameterValues("hobbys");
        System.out.println("===========");
        System.out.println(username);
        System.out.println(password);
        System.out.println(Arrays.toString(hobbys));
        System.out.println("============");
        //跳转语句
        req.getRequestDispatcher(req.getContextPath() + "success.jsp").forward(req,resp);
    }
}

跳转的前台页面

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

posted @   笑到肚子疼  阅读(9)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· AI Agent开发,如何调用三方的API Function,是通过提示词来发起调用的吗
点击右上角即可分享
微信分享提示