当前位置:网站首页>Blogs personal blog project details (servlet implementation)

Blogs personal blog project details (servlet implementation)

2022-06-24 23:09:00 The true story of a Zhai

 Insert picture description here

Related links

Project source code
Project public network address ( appear bug Please contact the blogger )
Project test point design ( Manual testing )

Blogs Personal blog project details

Description of project

function

The core functions are divided into 5 Plates , User registration function , User login function , Article list display function , Article details page function and article publishing function .

  1. User registration function : Users can set their own user name when registering 、 password 、 nickname 、 Head portrait address ( Picture address ) and git Address .
  2. User login function : The user can log in to the existing account through the user name and password .
  3. Article list display function : When the user logs in , Go to the user's home page . The home page will display the name of the blog posts that the user has published 、 Date and summary .
  4. Article details page : Users can click... From the blog list “ View full text ” Check the specific content of the blog .
  5. Article publishing function : Users can post blog posts , Specify the title of the blog post 、 Classification and text , The blog text supports Markdown Format .

technology

The main technologies involved are

  • Servlet
  • Thyleaf
  • JDBC
  • BCrypt
  • Cookie+Session

Project details

Code layering

The code layering of this project mainly refers to MVC The hierarchical way .V namely View View ,M namely model Model ,C namely controller controller . For example , If Web Application is a restaurant ,Web Resources are meals , that View The second floor is the waiter of this shop , For direct interaction with users ;C The layer is like a cook , For the processing of food materials ;M The first floor is the warehouse , Responsible for the delivery of food materials .

- View layer

View Layer users interact directly with users , In this project, there are basically Servlet Classes and HTML、CSS、JS Documents and pictures, etc .Servlet Class is a dynamic resource ,html、css and js The file is a static resource .

The difference between static resources and dynamic resources. Resources are generated in different ways . For example , hold Web Application as a restaurant , When the user goes to order , The ready-made meals provided by the hotel are static resources , The food prepared on the spot in the hotel is a dynamic resource .
The following is the of the project View The general classification and function of the class of the layer , Those who are interested can learn about .

Static resources

  • html file : It is used to realize the registration and login interface , It is specifically used to collect user input information . Since the registration and login interfaces do not involve user information , The content of resources is relatively fixed , So it is designed as a static resource .
  • css file : Used to beautify the page .
  • js file : This project uses js The purpose of this document is to support Markdown Format blog post publishing function .
  • Image resources : Again, just to beautify the interface .

Dynamic resources

  • Various types Servlet class : The main function is to accept the input information of the user , Transfer it to back-end processing , When the back-end processing is finished , Return the processing result of the business .

This project Serlvet Classes can be divided into two classes according to the technology involved , One class uses template rendering technology , The other is not used . There is no template rendering technology Servlet Class has only one function , Notify the processing result of a business , For example, log in 、 register 、 Cancellation 、 Preservation of articles ; Using template technology Servlet Class in addition to the notification function , There is also an additional display function , Using template rendering technology Servlet Class implements the article list display 、 Article details page and other functions .

- Control layer

Control The layer is mainly responsible for business processing , say concretely , It is based on View The need for layers , from Model Layer get data , Provide to after processing View layer . Generally speaking , This is the most difficult part of the project , It's also the core part . There are only two data subjects involved in this project , And the logic of data processing is not complicated . This project Servlet The layer includes AriticleService and UserService Two classes .

AriticleService

Responsible for article related business processing . Because this article according to the actual business needs , Three business functions are realized —— Get the article information of the article list page 、 Get the article information and article saving function of the article details page .
Get the article information of the article list page, including the total number of articles 、 Total number of articles classified 、 The title of each article 、 Time and summary . The article information on the article details page includes the title of the article 、 Time 、 Classification and text content .

UserService
Responsible for user related business processing . User business , This project realizes the simplest and necessary user operation —— register 、 Login and logout . Because this project does not need to record the user's login time , This operation does not require interaction with the back end , So the logout operation is not put into Service layer , And by the View Layer to operate . Login and registration involve database insertion and lookup , So put it in Servlet layer .

- Model layer

Responsible for direct interaction with data , In this project , It is equivalent to the interaction with the database . The data subject of this project is only articles and users , So we designed Model layer “”(Dao layer ) There are two classes ——ArticleDao and UserDao.

ArticleDao
Used for and MYSQL Direct database interaction , And MYSQL In the database articles Table correspondence , say concretely , That's right articles Addition, deletion, check and modification of tables . among Article The properties of the table include articles id、 title 、 type 、 Content and publication date .

UserDao
By analogy ArticleDao The role of classes , And users Table correspondence . among users The attributes of the table include the user id、 user name 、 password 、 nickname 、git Address and avatar address ( Picture address ).

Project evaluation

Bright spot

  1. Servlet technology . The technology of developing dynamic resources in this paper adopts the method of Servlet technology , As each Web The bottom layer of the development framework , It has great learning significance .
  2. Use MVC Code layering . The actual code quantity of this project is not large , But in terms of learning , Or divide the code into MVC Three levels , The code level is clear and logical , It also has great learning significance .
  3. utilize Cookie+Session Realize the automatic login function . Optimized user experience .
  4. Use BCrypt Technology encrypts passwords . To enhance the security of user information , The hash salt method is used to encrypt the database , Defensive measures have been taken against dragging the warehouse .
  5. The singleton design pattern is used for some objects , Improved code efficiency . The common characteristics of the objects of these classes are , Not as a hosted data container , Just to implement the business process . The objects of the implemented singleton pattern are Dao Layer objects and Service The object of the layer .

Insufficient ( Functional boundaries )

The boundary of the registration function

  • There is no limit on the length of each input , There are no restrictions on character types .
  • The security of passwords is not tested .
  • The user name specified by the current user cannot be verified in real time .
  • Register the specified avatar address and git Address has no validity detection .
  • The user can only specify the picture address when setting the avatar , You cannot specify a picture by uploading it , You cannot specify the crop range of the picture .

The boundary of login function

  • The same as the registration function , There are no restrictions on the length and character type of each input .
  • When the same user logs in to different clients at the same time , There will be no mutual exclusion .

The article list shows the functional boundaries

  • There is no limit to the number of articles .
  • Deleting and editing existing articles are not supported , And articles can only be sorted in ascending chronological order , You can't define the sequence of articles by yourself .
  • It does not support the function of article classification and article search .
  • Can't view other people's articles .

The article details the functional boundaries

  • When the text of the article is too long , The classification function is not supported .
  • The search function is not supported in the article .
  • Unable to view the specific category of the article .

Write about functional boundaries

  • There is no restriction on character types of the article title and length of the article body .

Problems encountered in the process

  1. Problems occurred when trying to connect to the ECS database
    Bloggers wanted to be in their own Windows On the host of the system Workbench Connect to the ECS MYSQL, However, in the process of connection, you will always be prompted with BUG. Looking for solutions online for a long time , The tried solutions include modifying the ECS MYSQL password , Reinstall the database on the ECS ,Windows None of the databases on the host have been resolved , In the end, it was necessary to reload Windows The system .
     Insert picture description here

  2. Solution : After trying for a long time , Giving up remote connection to ECs MYSQL Ideas , Want to learn directly in Linux Use the command line to operate the database directly on the . In the study Linux operation MYSQL After the basic command line and the method of creating tables and databases , Try to use the command line to create tables and databases directly on the ECS , And succeed .

  3. MYSQL Wrong sentence
    When self testing the project , Because I'm writing JDBC Time is not turned on MYSQL Statement correctness detection , Wrong writing MYSQL Statements are common . When MYSQL When it's wrong , If the corresponding DEBUG skill , Mistakes are often not so well positioned .

  4. Solution : At each execution MYSQL Statement before , All the things that are about to be carried out MYSQL Statement printed on IDEA On the console , When the project is self tested, the BUG, You can look at it IDEA Console . See what happens when the last one on the console prints , If it is MYSQL sentence , Then print the console MYSQL Copy the statement to WorkBench Let's see . If the statement execution fails , It can be determined that the basic is MYSQL The question of sentence .

  5. It's not set up Context Path Produced url error
    Because bloggers are just beginning to Servlet My understanding is not deep , Yes Servlet in Context Path The role of , Sometimes I make mistakes url, Lead to 404 Error of .

  6. Solution : In case of 404 And know the cause of the problem , Yes Servlet Of Context Path The role and importance of , After that, they seldom appear 404 Wrong. .

  7. The registration and login functions are not interconnected , Impact on user experience
    After the core functions of the project are completed , Bloggers have found that there is a strong correlation between login and registration functions , If the login page does not have an entry for the registration function or the registration page does not have an entry for the login function , It affects the user experience .

  8. Solution : In the following , The blogger provides the registration function entry in the login page , The login function entry is provided in the registration page , Realize the interoperability of registration function and login function .

Project test point design

Blog links

Project gains

  1. Comprehensive application of various theoretical knowledge , Include database 、HTTP theory 、 Front three swordsmen (HTML、CSS、JS) and Cookie+Session etc. , Yes JavaWeb The understanding of the project has been further improved .
  2. Learning and understanding the idea of project design , Including the idea of code layering 、 Library table design method and top-down design method .
  3. It improves the ability of designing test cases .
  4. Cultivate their ability to solve problems independently , Including channels for finding information , How to locate the problem and how to solve it .
  5. Understand the password encryption technology , To enhance their horizons .
原网站

版权声明
本文为[The true story of a Zhai]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202211145062442.html