Use SSM framework to realize user login function

Create database and tables

(1) Database creation

1. Create database and user table


 2. User added record

 (2) Create a Maven project

 (3) Add related dependencies

Add related dependencies to the pom.xml file

Open the Maven window, click the refresh button, and download dependencies

 (4) Create a log attribute file

Create a log4j.properties file in the resources directory

 (5) Create a database configuration property file

Create the jdbc.properties file in the recourse directory

 

(6) Adding Web functions to the project

Click the project Structure button on the toolbar

Click the Create-Artifact button

Rename the default SSMLogin.Web exploded to SSMLogin

WEB-INFThe subdirectories in the directory classescontain the compiled bytecode files of source programs written by users, but jarthe packages that the project depends on need to create a libdirectory

Select all on the right Available Elements, right-click, and a shortcut menu will pop up

Click Put into /WEB-INF/libthe menu item to add the selected jarpackage to /WEB-INF/libthe directory on the left

(7) Configure the Tomcat server

1. Install the Tomcat server

Download tomcat-8.5.58.rar, extract it to the root directory of D drive

Enter the executable directory bin

 Configure Tomcat environment variables

2. Start the Tomcat service

Execute in the command window: startup.bat, start the Tomcat service

In addition, a command line window will pop up, displaying Tomcat startup information

3. Visit the Tomcat home page

(1) The home page is in D:\tomcat-8.5.58\webapps\ROOTthe directory

(2) How does the client request (request) the dynamic web page placed on the serverindex.jsp

(3) The default port of the Tomcat server is 8080, server.xmlwhich can be modified in the configuration file

4. Static resources

Create a py subdirectory in webappsthe directory and put some static resources in it

 (8) Create a user entity class

 Create net.py.ssm1.bean and create a User class in the package

(9) Create user mapper interface

Create net.py.ssm1.mapper, create UserMapper interface in the package

 (10) Create a user service class

Create a service subpackage in net.py.ssm1, and then create a userservice class in the subpackage

 (11) Create a user controller

Create a controller subpackage in the net.py.ssm1 package, and then create a usercontroller class in the subpackage

 (12) Create a user mapper configuration file

Create a mapper subdirectory in resources, and then create usermapper.xml in the subdirectory

 (13) Prepare static resources

1. Prepare image resources

Create an images directory in WEB-INF to store image resources-bear.png

2. Create a style file

Create a css subdirectory in WEB-INF, and then create login.css in the subdirectory

 3. Create a script file

Create a js subdirectory in WEB-INF, and then create check.js in the subdirectory

 (14) Create a page

1. Create a directory structure

Create the views subdirectory in WEB-INF, and create two subdirectories, frontend and backend, in views

2. Create the homepage of the website

 3. Create a background management page

views/backendcreated inmanagement.jsp

 (15) Create a spring configuration file

resourcesCreate subdirectories inside , configand then inside subdirectoriesspring-config.xml

(16) Create a springMVC configuration file

create in resources/configdirectoryspring-mvc-config.xml

 (17) Edit the Web deployment description file

 (18) Start the server and check the effect

Set the <welcome-file>/WEB-INF/views/frontend/login.jsp <welcome-file> element in the culture, so the login page will be displayed first

non-null check

 

Login failed

 Enter the correct username and password

 

 


Guess you like

Origin blog.csdn.net/py20010218/article/details/125130246