简体   繁体   English

如何使用数据库检查用户名和密码以显示错误消息?

[英]How to check username and password with database to display error message?

I created a login page(HTML) in dynamic project. 我在动态项目中创建了一个登录页面(HTML)。 I want to check username and password with mysql database and display error message on the same page if username or password are incorrect. 我想用mysql数据库检查用户名和密码,如果用户名或密码不正确,则在同一页面上显示错误消息。 I don't want to use servlet here to display the error page because I want to display error message instead of error page. 我不想在这里使用servlet来显示错误页面,因为我想显示错误消息而不是错误页面。 How can I achieve this in dynamic webproject. 如何在动态Web项目中实现这一目标。 Can I use javascript, jQuery, JSP, or any combination of these? 我可以使用javascript,jQuery,JSP或这些的任意组合吗?

I am not familiar with JSP but here is an overview of what you need: 我不熟悉JSP,但是这里是您需要的概述:

index.html 的index.html

<!DOCTYPE HTML>
<html>
    <head>
        <title>Web Form</title>
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
        <script>
            $(document).ready(function() {

                $('form').on('submit', function(e) {
                    // don't let the browser submit the form
                    e.preventDefault();

                    // send form data to JSP page
                    $.ajax({
                        url: 'process.jsp',
                        async: true,
                        cache: false,
                        type: 'POST',
                        data: $(this).serialize(),
                        dataType: 'html',
                        success: function(data) {
                            // place message in error box
                            $('#error_box').html(data);

                            // if "Success" then redirect if you would like
                            if(data === 'Success!'){
                                // window.location = 'some other page/website';
                            }
                        }
                    });
                });

            });
        </script>
    </head>

    <body>
        <form method="POST" action="process.jsp">
            <input type="text" name="username" />
            <input type="password" name="password" />
            <input type="submit" value="submit" />
        </form>
        <div id="error_box"></div>
    </body>
</html>

process.jsp process.jsp

// I don't know JSP
// use the POST values and check your DB
// Upon success/failure just echo the message
// <%='Success!'%>
// <%='Failed!'%>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在工具提示中显示错误消息以确认密码? - How to display error message in tooltip for confirm password? 如果流星用户名中已经存在用户名,如何显示错误消息 - How to display error message if username already exists in meteor-ionic 挣扎一些JavaScript,密码/用户名错误显示 - Struggling with some javascript, password / username error display 要求的用户名和密码显示什么信息? - What do display message of Username required & Password required? 键入用户名时如何显示密码? - How to display password while typing username? 我如何调用 API 并在 javascript 中使用数据库检查用户名和密码? - How do I go about calling API and check username and password with Database in javascript? 如何显示来自 javascript MDL 文本字段的错误密码错误消息 - How to display wrong password error message from javascript MDL textfield 如何在Axios中使用用户名和密码访问数据库 - How to access database with username and password in Axios 仅当使用jquery未正确输入用户名或密码时,如何显示错误消息? - How can I get my error messages to display only if username or password is not entered correctly using jquery? Qualtrics API v2.5中的“用户名或密码错误”错误消息 - “Incorrect username or password” error message in Qualtrics API v2.5
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM