Java Web (IX) user management system

I learned a lot about JSPS, servlets, JSTL, El, etc. most of them are dead things. As long as I can understand its syntax and know how to use it, I made a small demo with only addition, deletion, modification and query in order to be familiar with these knowledge. Flexible use. The most important thing is the development idea and technology. After we get the demo requirements, how should we start, think and develop? I wrote down my thoughts when I wrote the demo.

                                  --WZY

1、 Demand analysis

I've said a little. It's very simple. I'm talking about the use of addition, deletion, modification and query,

Register, log in, query all users, query details, modify and delete

There are two permissions,

One authority is administrator authority. After logging into the system, you can see the information of all users, and can modify and delete the information of all users.

The other is ordinary user permission. When you log in to the system, you can only see your own relevant information and modify your own information (password, etc.)

Master page module

The first entry is the main page module, which will judge whether the user logs in (check whether the information of the user's account and password exists in the cookie. If so, log in directly with the account password. If not, no data will be displayed)

After logging in, the administrator can see all user information, view the details of any user, modify and delete users, and have the function of registration

Ordinary users can only view their own relevant information when logging into the main page. It can modify information. However, there is no function to register and delete users.

Login module,

Login will judge whether it is an administrator or an ordinary user, and it has the function of remembering the password. Click remember the password, then you will have logged in the next time you visit the main page, and use cookies to remember the account password.

When writing the account password, it will be checked (check whether the account password format is qualified. This is not done. You can do it if you are interested)

What the login module does is very simple. Judge whether the account password is correct. If it is correct, it will jump to the main page and save the user information to the session to judge whether it remembers the password. If it remembers the password, it should save the account password to the cookie. Determine whether you are an administrator or a user.

Registration module

Only administrators have the right to do this. The registration module is very simple, which is to add users. Only when registering and filling in information, data verification needs to be done to restrict users from entering some illegal data. I didn't do it. People with leisure can do it.

2、 Technical analysis

Three tier architecture

    JSP(jstl、el)

    Servlet(request、response、session/cookie)

    javabean

    JDBC

    MysqL

3、 Writing ideas

1. First write out all the package structures, which generally looks like the idea of three-tier architecture. The jar package of MySQL that needs to be imported is also imported

2. Start from Dao,

Successfully connected to MySQL database

The common methods of addition, deletion, modification and query are written and tested successfully

3. Write the service layer

Because this demo is too simple and has no business logic, the service layer actually calls the addition, deletion, modification and query methods of the Dao layer.

4. Write the web layer, one module at a time

Home module

The user is not logged in, as shown in the figure. Two hyperlinks, please log in and home page, will be displayed in the upper left corner. The home page is to return to the home page. Please log in is to jump to the login page

After ordinary users log in, the home page is displayed as shown in the figure. Their own information will be identified in red font, and their permission can only view their own details and modify some information. In the upper left corner, your name will be displayed and you can log out. Logging out is to log the user off the line and log in with another account

After the administrator logs in, the home page is displayed as shown in the figure. The administrator can see the information of all users, modify and delete them, but does not delete themselves. Moreover, the administrator will have the function of registering users.                  

Registration module

This is very simple, but the defect is that there is no data verification function. Only correct information can be filled in. For example, no information is filled in, and no prompt information appears. This is very bad. And the background will report an exception.

Login module

This is actually a technology. Remember the password. Here, cookie technology is used. The account password was saved to a cookie. After logging in, you will jump to the main page to display the information.

Query module

This is to query the user's details. If you can, you can expand it yourself. For example, query the information of the user name through the user name. Use fuzzy query, etc. here is the simplest.

Modification

Delete it directly..

4、 Summary

This small user management took me a day to write independently. In fact, if I am familiar with the business process, it won't take that long. It's estimated that it will take less than 2 hours to write it. Although there are only a few functions of adding, deleting, modifying and checking, it's for novices, It's good to make yourself more proficient in mastering and learning knowledge through this. It uses a lot of basic things. For example, in the front-end display page, the tag and El are used, and the data is put into the session field. We can get the data we want through the El expression. For example, in the background, cookies are used to save the account and password. For example, the use of request forwarding and redirection, such as the transmission of values in the request field, such as the use of request to obtain request parameters, such as the use of some CSS in the front-end page, For example, the operation of connecting to the database, the operation of adding, deleting, modifying and querying the database, and the native and oldest writing method. It's really tiring. It's all repetitive code, but you will know the difference between preparestatement and statement, and why you use preparestatement instead of statement. The most important gain is that the large and small processes make me very confused. When writing the main page, because several pages will jump to the main page, such as the login page. After logging in, we will jump to the main page. For example, if we visit directly, we will also go to the main page. Then the two are different. If we visit the main page directly, we need to judge whether the information in the cookie is used, After logging in to the main page, I have to judge whether the account password is correct, whether it is an administrator, how much data to display, and so on. I have written it all in a loginservlet, resulting in a huge amount of code. It is estimated that only I can understand it. Ha ha ~ but the function process is probably completed. The only disadvantage of being able to run and achieve the expected results is that it is too chaotic. I am not very clear about the process. Later, I believe I will become more and more proficient. Writing a login module, what functions should be required and what judgments should be made should be practice makes perfect. Come on.

The source code of the project is placed below

         http://pan.baidu.com/s/1kVNp4zX Password: 3ocx

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>