A simple login interface for Javaweb development the tools used here are eclipse, SQL 2016, tomcat8
Before development, you need to complete the connection configuration of Tomcat and SQL in Eclipse, where Tomcat starts automatically when the Web project runs, and the development steps are described below
First, the establishment of Web projects
Open Eclipse Point solution file->new->dynamic Web Project
Enter the project name by entering the following interface
Click Next
Then click Next to go to the next screen
Select the location where the arrows point, click Finish, and complete the creation of the Web project
Third, database Building table
Open database Right-click Database New Database
Click New Database, right click on table--new table
Enter a column name here, select a good data type
Enter information after opening
Save and complete the database table establishment
Iv. Database Connection
Drag the Sqljdbc4.jar file into the Web-inf
V. Add a JSP file
Right-click WebContent
Finish completing the JSP file creation
Enter the following code when the creation is complete
<%@ page language= "java" contenttype= "text/html; Charset=utf-8 " pageencoding=" Utf-8 "%><! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" >User: <input type= "text" name = "username" ><br> password: <input type= "password" name= "pass" ><br> <input type= "Submit" value= "Login" ></form></center></body>
Run, can complete the creation of the interface
Enter the code
<%@ page language= "Java"Import= "java.sql.*" contenttype= "text/html; Charset=utf-8 "pageencoding= "UTF-8"%><! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" >String drivername= "Com.microsoft.sqlserver.jdbc.SQLServerDriver"; String Dburl= "Jdbc:sqlserver://localhost:1433;databasename=hh"; String UserName= "SA";//Database login account password String userpwd= "g15034014195"; Class.forName (drivername); Connection Dbconn=drivermanager.getconnection (DBURL,USERNAME,USERPWD); String SQL= "SELECT * from log where [user]=? And [pass]=?]//user Pass represents the column name created in the database
PreparedStatement pstmt=dbconn.preparestatement (SQL); Request.setcharacterencoding ("UTF-8");
String User= Request.getparameter ("username");
String Pass= Request.getparameter ("Pass"); Pstmt.setstring (1, user);
Pstmt.setstring (2, pass);
ResultSet RS=Pstmt.executequery ();
if(Rs.next ()) {%><center> } Else { %><center> } %> </body> The operation results are as follows
Simple Java Web Implementation interface development