Java Web simple de login Registration
Recently I wrote a simple login Registration
The implementation result is as follows:
**************************************** * Part 1: effect *************************************** ****
Logon and registration page:
Login successful and registration successful page:
(Return to the logon page after successful registration)
************************************ Part 2: implement *************************************** *****
Login and registration are two basic functions that can be expanded on this basis,
Logon registration is implemented in the following three parts,
Basic java interfaces and Classes
Mysql database connection
Jsp and servlet
1. First, database creation and Connection
(Data must be submitted to the server for login and registration, and the server takes the remaining database data for related operations)
Taking my program as an example, first create a user Table (student user) in the Database, Database: Mysql3 Table: student
Set two attributes: String name and String password;
Initialize some data.
After the database and related tables are processed, create a web project in MyEclipse. Other code is written on this platform (you can also use eclipse)
Create a new package cn.edu. hpu. model name (custom servlet jsp project name class interfence name is created below)
1. Used to write the student class, corresponding to the table created,
2. Establish a database connection so that the server can query and use the database data.
(Database connections are divided into three parts: loading drivers; Creating connection objects; and other related objects; and closing opened data streams)
3. New Package cn.edu. hpu. test write test connection code, in/test/WebRoot/WEB-INF/lib import database connection *. jar File
//////////////////////////////////////// //////////////////////////////////
Create cn.edu. hpu. service
Write an interface in the package, and add ckeckLogin two methods to register 'logon
Create a class to implement the interface
//////////////////////////////////////// //////////////////////////////////////// //
Test the above two methods
1.
2.
Related Verification
Finally, create jsp and the corresponding servlet
The Code is as follows: note that changing pageEncoding to UTF-8 supports Chinese characters to prevent garbled characters.
/////////////////////
***/////
//////////////////////////////////////// ////////////////////////////////////////
/////
//////////////////////////////////////// ////////////////////////////
Servlet:
//////////////////////////////////////// //////////////////////////////////
Xml files are automatically generated in Myeclipse. Other platforms may need to write them by themselves.
The Code is as follows:
A series of errors or exceptions may occur due to incorrect path or case sensitivity. The above code is free of errors. Pay attention to the code writing standards to develop a good style.