Recently wrote a simple login to register
The implementation results are as follows:
The first part: effect *******************************************
Login and Registration interface:
Login success and Registration successful interface:
(Login interface is returned after successful registration)
Part Two: Realizing ********************************************
Login and registration is the two most basic functions, can be based on this to expand,
The implementation of login registration, mainly divided into the following 3 parts,
Java Foundation interfaces and classes
Database Mysql Connection
JSP and Servlet
1. First, create and connect the database
(Login and registration to submit data to the server, the server to take the rest of the database data related operations)
Take my program as an example first set up a user table in the database (student user), Database:mysql3 table:student
Set two properties of String name; String password;
Initialize some of the data.
After the database and related tables are processed, create a Web project project in MyEclipse, and other code is written on this platform (also available in eclipse)
New Package Cn.edu.hpu.model name customization (following new servlet JSP project name class interfence name customization)
1. Used to write the student class, the corresponding built table,
2. Then establish a connection to the database so that the server query uses the database data
(The database connection is divided into three parts, one is to load the driver two is to create the connection object, and other related objects three is to close the Open data stream)
3. Create a new package Cn.edu.hpu.test write the code of the test connection, import the *.jar file of the database connection in/test/webroot/web-inf/lib
//////////////////////////////////////////////////////////////////////////
New Package Cn.edu.hpu.service
Write an interface in the package, and two methods add ckecklogin corresponding registration ' login
Create a new class that implements an interface
//////////////////////////////////////////////////////////////////////////////////
Test the above two methods
1.
2.
Related validation
Finally, create the JSP and the corresponding servlet
The code is as follows: note Change pageencoding to Utf-8 support Chinese to prevent garbled characters
/////////////////////
***/////
////////////////////////////////////////////////////////////////////////////////
/////
////////////////////////////////////////////////////////////////////
Servlet:
//////////////////////////////////////////////////////////////////////////
XML files are automatically generated in MyEclipse, and other platforms may have to write their own
The code is as follows:
Due to the path problem, casing problems, such as writing irregularities may lead to a series of errors, exceptions, the above code can be used without errors, please pay attention to code writing specifications, form a good style
Javaweb simple de sign-in registration