First we need to write a simple landing page login.jsp, and then submit the from form to the index.jsp page. In the index.jsp page through the DBHelper connection database to determine the account number and password, if the password is correct to display the login success.
The following is the landing page code
<base href= "<%=basePath%>" >
<title> Landing Page </title>
<body>
Submit user name password to index.jsp
<form action= "index.jsp" Name= "Form1" method= "POST" >
<div >
<a> user:</a><br> <input class= "YH" type= "text" value= "" name= "username"/><br>
<a> password:</a><br> <input class= "ma" type= "password" value= "" name= "password"/><br>
<input class= "DL1" type= "submit" value= "Login"/>
</div>
</form>
</body>
:
Here is the code for INDEX.JSP:
<%@ page language= "java" import= "java.util.*,dbhelper.*,java.sql.*" 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" >
<base href= "<%=basePath%>" >
<title> Verification Page </title>
<body>
<%
String sql= "SELECT * from user WHERE username=? and password=? ";
String uid=request.getparameter ("UID");
String pwd=request.getparameter ("pwd");
Object[] Params=new object[]{uid,pwd};
ResultSet Rs=dbhelper.getresultset (Sql,params);
if (Rs.next ())
Out.print ("Login Successful");
Else
Out.print ("Login Failed");
Rs.close ();
%>
</body>
Then copy the DBHelper package to the SRC folder
Replace the user name and password in the DBHelper code with your MySQL database.
Then you can run it.
I run the results
Using DBHelper to implement login functions in JSP pages