A Use DBHelper with MySQL connection for the simplest login verification.
(1) Create a new Web project-----> select the SRC Import dbhelper toolkit--------> select Create a form (username, password, and button) from index.jsp under Web root--------> Use the action to submit this page to login.jsp for validation of the user name and password correctness. The specific operation code is as follows:
1. index.jsp
<body>
<form action= "login.jsp" method= "POST" >
User name: <input type= "text" name= "username" ><br>
Secret code: <input type= "password" name= "pwd" ><br>
<input type= "Submit" name= "commit" value= "Login" >
</form>
</body>
2. login.jsp
(In this link, you need to pay attention to import Dbhelper,resultset Toolkit, otherwise will be error; The table name "users" in the database is consistent with the table name in SQL, and the field name "username" "Password" is also unified, And pass these two parameters to the result set resultset, finally determine whether the RS exists in the database)
<% @page import= "Java.sql.ResultSet"%>
<%@ page language= "java" import= "java.util.*,dbhelper.*" pageencoding= "UTF-8"%>
<body>
<%
String sql= "SELECT * from users where username =? and password=? ";
String User=request.getparameter ("username");
String pwd=request.getparameter ("pwd");
Object[] Obj=new object[]{user,pwd};
ResultSet rs = dbhelper.getresultset (sql, obj);
if (Rs.next ())
Out.print ("Login Successful! ");
Else
Out.print ("Login Failed");
Rs.close ();
%>
</body>
3.users table
Username password
Admin 123
Note: The Users table has username, password two field names, and the name matches the parameter name obtained in the request method in login.jsp. And there is a record: "username": admin; Password ": 123.
(2) Start running (commissioning)
1. When you enter a field name such as "Jack", "Linda" in the text box of "user name", or enter "AAA", "111" in the Password box, the "Login failed" prompt statement will appear;
2. Only the user name "admin" and password "123" are entered in the database, the system will appear "Login successful!" "It also means that the verification is successful!"
March 9 (Use DBHelper tool to connect MySQL database for login verification)