javaWeb project >_ < Project with me (super detail - Episode 1)

0 overview

	Make one jiavaweb You can finish the hand training project javaweb The application of knowledge points in the project can also exercise the logical idea of function realization. Let's take a look at the effect diagram below

	The project is divided into two parts. The first part mainly completes the function of student management, and the next part mainly completes the function of defining permissions

1 Preparation

stores reserve

Link: https://pan.baidu.com/s/1il4X8OlVtkB1mzaAH4Fz_Q
Extraction code: kpt7

 This way, I put all the needs to complete the project(front end)+(back-end)The code and database are placed in the network disk and placed in the github There may be a bad network or something. It's troublesome
 There are in the front of the figure below html and jsp ,We javaweb Inside use jsp
 	 lib Are some dependent packages to be used, mysql Depending on your version,
 	 Connection pool with Druids, database SQL All the papers are ready

Skill stack and tool stack

1.database
2.JDBC
3.html
4.servlet
5.JSP+EL+JSTL
6.AJAX
7.Multi table operation

Required tools
1.idea
2.Navicat
3.Tomcat
4.mysql

Database data preparation

You can run it directly from me SQL File in Navicat Run inside, and then add the additional data you want to add
 Let's analyze here. There is one table for login identity and two tables for students

idea class preparation after project creation

src Build 5 packages
web Prepare the above materials for the inside jsp What's in the folder web inside
	hold lib What's inside WEB_INF It's better inside

You have to write classes according to the data flow, layer by layer

Class, see source code backup for details hjg01,Look inside int --> Ingiter It would be better

lib Package dependent import

Tomcat set up

2 login and exit function (code hjg01)

[login]

First modify login jsp

Add < form > and "/ login"

Modify the two input s inside to receive the user name and password entered on the front-end page

Then add two web tier classes LoginSerlet to log in Logout to exit

LoginSerlet links login through @ WebServlet(urlPatterns = "/login") jsp

LoginSerlet rewrites the service to undertake three tasks

@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    //1. Receiving parameters
    //2. Call servlet business layer
    //3. Jump to page
}

Receive two parameters from the front end

//1. Receiving parameters
String username = req.getParameter("username");
String password = req.getParameter("password");

Business layer transfer

//2. Call servlet business layer
UsersService usersService = new UsersServiceImpl();
Users users = usersService.login(username, password);

You need to write the web service dao layer by layer

First, add the login method to the abstract class

Implementation class implementation method -- the embarrassing thing is that the service business layer needs to get data from the dao layer,

Therefore, you have to add dao abstract classes and dao implementation classes to implement methods, so as to write a druid linked database

Attention this way DBUtils of resultSet use protected modification

Come back to the web layer and write jump pages

If there is no such person in the database, a pop-up window will remind you

If the user authentication is successful, set a u1 for global access

Results to front end

Start Tomcat run project

There is no user test in the input database, pop-up reminder

Log in successfully, enter the next page, save the data and display it on the front end

Here, if we click the exit button, there will be no response and an error will be reported. Next, we will perform the exit function

[exit]

Similar to login, let's modify the front end first

Write the logout class of the web layer

The front end we use here has a frame, and the top indicated by the arrow exits directly to the outermost layer

3 student list display (code hjg02)

<1> Modify list jsp

<2> Add web class GetStudentServlet

<3> Add corresponding methods to extract student information in service layer and dao layer

<4> Writing servlet layer code

<5> Modify the front-end display code for display

Note: gender must be converted from 0 to 1 characters 

<6> Run to view results

4. Implementation of fuzzy query (code hjg03)

<1> Modify list JSP page to receive data and display the saved data

<2> Method to add parameters

<3> Modify the service layer and dao layer and add corresponding methods to extract student information

<4> Running results (all women)

reflection

In addition to the above ambiguity, fuzzy query can also be set to 3 conditions, 2 conditions and 1 condition. It is mainly used to adjust SQL statements. You can expand it yourself

5 set paging function (code hjg04)

<1> Display the last written list JSP, which will be used one by one

<2> Add parameter

<3> Modify the service layer and dao layer and add corresponding methods to extract student information





<4> Store paging data, add previous page to next page

Here, pay attention to the method of limiting the number of pages out of bounds. In the next step, we need to use the total number of pages, so we have to write the code to get the total number of pages

<5> Get total pages

<6> Modify the service layer and dao layer and add corresponding methods to extract student information



Don't forget to store values to the front end

Don't forget to add fuzzy search parameters in the paging button

<7> Operation results


6 new student (code hjg05)

<1> Modify list and add classes and methods


<2> Modify the corresponding service layer and dao layer and add the corresponding query grade list





<3> Modify add JSP display data

At this time, if you change the grade data in the database, you can see the results immediately after refreshing in the browser

<4> Modify add jsp

Modify the corresponding attribute one by one. This is only a part

<5> Add the servlet class corresponding to add

<6> Add the corresponding insertStu call method to the corresponding service layer and dao layer

<7> Operation results

7 primary key query (code hjg06)

Before modifying, updating and deleting data, we first complete the primary key query function of a specific person's data from the database

<1> Modify list

<2> Add FindByIdServlet class

<3> The method of adding the corresponding PK query to the corresponding service layer and dao layer




<4> Write servlet coordination edit jsp

edit.jsp First adjust the stored value of each attribute, receive the data from the back end and display it. This is only part

Pay attention to the acquisition of the class

<5> Effect display

8 modify and update data code (hjg07)

<1> Modify front end edit

<2> Create classes and write code

<3> Add the corresponding method of modifying students to the corresponding service layer and dao layer





<4> Run to see the results (click Modify)

9 delete student data (false deletion) (hjg08)

<1> Enumeration value to save student status (reading, dropping out...)

I don't know if you have found this enumeration operation in the addition operation, which is also used in the deletion


delete

<2> Modify list

<3> Add the corresponding "delete student" method to the corresponding service layer and dao layer




<4> When querying, switch to state to limit

<5> Run view


10 use filter to deal with garbled code (hjg09)

In addition and modification, it is easy to appear garbled code. We have to add it every time         req.setCharacterEncoding("utf-8");  

It's a little troublesome. We can use the filter, create a new package, create a new class, and modify the configuration file


11 multiple requests go to the same servlet

back-end




front end







Remember to run and see

12 pagination tool class



13. Things that can be improved

<1> New - student number cannot be repeated (solved with AJAX)

<2> Student management can also enter when there is no login (you have to add restrictions). It is not added in front for the fast running function

<3> Be patient with bug s

Keywords: Java JavaEE Tomcat intellij-idea

Added by firelior on Mon, 17 Jan 2022 09:10:51 +0200