前端向后端传递数据

form提交

前端:

<!--用table布局、 label的inline-block 对齐input-->
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8" />
    <title>Title</title>
</head>
<body>
<div class="web_login">
    <ul>
        <ul>
            <!--accept-charset 属性规定服务器处理表单数据所接受的字符集.此属性的默认值是
            "unknown",表示表单的字符集与包含表单的文档的字符集相同-->
            <form name="form2" accept-charset="utf-8"  action="/security/addregister" method="post">
                <!--用table对齐-->
                <table >
                    <tr>
                        <td>用户名:</td>
                        <td><input type="text" name="username" maxlength="16"/></td>
                    </tr>
                    <tr>
                        <td>密码:</td>
                        <td><input type="password" name="password1" maxlength="16" /></td>
                    </tr>
                    <tr>
                        <td>确认密码:</td>
                        <td><input type="password" name="password2" maxlength="16" /></td>
                    </tr>
                </table>

                <div class="inputArea">
                    <a th:href="@{/security/readdoc}" target="_blank">阅读注册协议</a>
                    <input type="submit" value="同意协议并注册"/>
                </div>
            </form>
        </ul>
    </ul>
</div>
</body>
</html>

 

后端:

    @RequestMapping("/addregister")
    public String register(HttpServletRequest request){
        String username = request.getParameter("username");
        String password1 = request.getParameter("password1");
        String password2 = request.getParameter("password2");
        if (password1.equals(password2))
        {
            User1 user = new User1();
            user.setUserName(username);
            user.setUserPwd(password1);
            userService.addUser(user);
            return "login";
        }
        else
        {
            return "register";
        }
    }

 

前端向后端传递数据

上一篇:安装了vs2019 编译node-sass node-gyp 找不到编译器的解决方法


下一篇:【TVM模型编译】2. relay算子构造.md