• AJAX实现模拟注册跳转


    前端页面

    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
    <%
        String path = request.getContextPath();
        String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    %>
    
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
        <base href="<%=basePath%>">
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>注册页面</title>
        <link rel="stylesheet" href="<%=basePath%>css/bootstrap.min.css">
        <script src="<%=basePath%>js/jquery-1.11.0.min.js"></script>
        <script src="<%=basePath%>js/bootstrap.min.js"></script>
    </head>
    <body>
    <script language="javascript">
        function Register(){
            var username=$('#username').val();
            var password=$('#psw').val();
            var password1=$('#psw1').val();
            if(password!=password1){
                alert("两次密码不一致!")
            }else
                $.ajax({
                    type: "post",
                    url: "/register",
                    data :JSON.stringify({username:username,password:password}),
                    contentType : "application/json;charset=UTF-8",
                    dataType: "json",
                    success : function(data){
                        alert("注册成功!");
                        window.location.href = "/z";
                    }
                })
        }
    
    </script>
    <div class="container">
    
    
        <div class="row clearfix">
            <div class="col-md-12 column">
                <div class="panel  panel-info">
                    <div class="panel-heading">
                        <h3 class="panel-title">
                            login
                        </h3>
                    </div>
                    <div class="panel-body">
                        <div class="col-md-12 column">
                            <form class="form-horizontal" role="form"  action="" method="post">
    
                                <div class="form-group">
                                    <label      class="col-sm-2 control-label">用户名:</label>
                                    <div class="col-sm-10">
                                        <input type="text" class="form-control " name="username" id="username" />
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label  class="col-sm-2 control-label">密码:</label>
                                    <div class="col-sm-10">
                                        <input type="password" class="form-control" name="password"  id="psw" />
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label  class="col-sm-2 control-label">确认密码:</label>
                                    <div class="col-sm-10">
                                        <input type="password" class="form-control" name="password"  id="psw1" />
                                    </div>
                                </div>
                                <div class="form-group">
                                    <div class="col-sm-offset-2 col-sm-10">
                                        <div class="checkbox">
                                            <label><input type="checkbox" />Remember me</label>
                                        </div>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <div class="col-sm-offset-2 col-sm-10">
                                        <button type="button" class="btn btn-default" onclick="Register()" >注册</button>
                                        <a href="/">已有账号?返回登陆</a>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                    <div class="panel-footer">
                        Panel footer
                    </div>
                </div>
            </div>
        </div>
        <div class="row clearfix">
    
        </div>
    </div>
    
    </body>
    </html>

    控制层:

        @RequestMapping(value = "/register")
        @ResponseBody
        public User register( @ModelAttribute User user, Model model)  {
            model.addAttribute("user",user);
            return user;
            
        }
    不经一番彻骨寒,哪有梅花扑鼻香?
  • 相关阅读:
    36.百马百担问题。有100匹马,驮100担货,大马驮3担,中马驮2担,两匹小马驮1担,问有大中小马多少匹,共有多少组解?
    35.鸡兔同笼问题:今有雉兔同笼,上有三十五头,下有九十四足,问雉兔各几何?
    34.设s=1+1/2+1/3+…+1/n,求与8最接近的s的值及与之对应的n值
    33.求1*2+2*3+3*4+……前n项的和
    32.求1+(1+2)+(1+2+3)+(1+2+3+4)+……的前n项的和
    31.假定2007年的一月一日是星期一,输入一个时间(包含年、月、日),求出它是星期几。
    vue-cli3 一直运行 /sockjs-node/info?t= 解决方案
    python pdf转word
    window django-https 证书
    Docker技术应用场景(转载)
  • 原文地址:https://www.cnblogs.com/zongyao/p/13831139.html
Copyright © 2020-2023  润新知