1

I am developing a web application and created a Login page using HTML. The back-end is MySQL. Already established connection with the database using connection string and able to fetch data from MySQL(Through java program). I have to compare the entered username and password values with those in users table(MySQL). How can i get these entered values inside the java classes(where the database connection is established)

$(document).ready(function() {
    $('#submit').click(function() {
        var userValue = document.getElementById('nameuser').value;
        var passValue = document.getElementById('passid').value;
        $.ajax({
            //code 
        });
    });
});

how can I achieve user authentication in such a scenario? Hoping this can be achieved with jQuery and Ajax. Needless to say, I am an amateur in Java and related technologies.

2 Answers 2

1

Pass your data via ajax and run the sql select * from tbl_user where username=$_POST['userValue'] and password=$_POST['passValue'] you need not compare the values if the result obtained for those combinations user exists else no user available display wrong username password alert.

             $.ajax({
                url: "url to link your database",
                type: "POST",
                data:{'userValue':userValue,'passValue':passValue},
                success: function(result) {
                }
             })
Sign up to request clarification or add additional context in comments.

Comments

1
$.ajax({
            url: "localhost:8080/yourProjectName/checkPasswordServlet",
            type: "POST",
            data:{'userValue':userValue,'passValue':passValue},
            success: function(result) {
                 console.log(result)
            }
         })

at the end side,if you use tomcat for http server, you can try servlet to receive data:
1.config the web.xml like this:

<servlet>
    <servlet-name>checkPasswordServlet</servlet-name>
    <servlet-class>com.demo.login.checkPasswordServlet</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>checkPasswordServlet</servlet-name>
    <url-pattern>/checkPasswordServlet</url-pattern>
</servlet-mapping>

2.in servlet like this:

 String userValue= request.getParameter("userValue");
 String passValue= request.getParameter("passValue");

3.compare with your data which from database,and return compare result to front side.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.