Analyze and learn JPETSTORE management management in Spring

zhaozj2021-02-16  59

There is a user's system that inevitably requires users' login and authentication. Today, you will learn how to log in in the system of the Spring architecture by analyzing the JPetStore from Spring.

1. First, start from the registered user, first look at the bean definition of the registered user in JPETSTORE-Servlet.xml. From the defined name, you can see that the following is the registered user: < Ref bean = "accountvalidator" /> index 1). Formview? Get it from the constructor of AccountformController, it is an editaccountform; 2). EDITOACCOUNTFORM.JSP is very chaotic, in fact, there is not much difficult understanding, the most important thing is that this form is both add new users, and editing user information. So it looks a bit messy.

2, add a new user, then look at how to log in, discover both related beans definitions in the jpetstore-servlet, as follows: sign " 1). The second bean is in runtime user input FORM of the username and password called SignonForm, for this parameterizableviewcontroller, in the document, this is the simplest controller, its role is to point to Controller instead of the JSP file in the run, just this.

2). Signonform.jsp, it is a simple form. It is the first bean, ie /shop/signon.do, and the most important thing to note is SignonForwardAction. Its main role is that forward to enter the username and password. On the page, where is this variable? Consider the following: The above SignInterceptor implemented PreHandle, so when the MAP page is requested, First of all, I have to go through this interceptor, take a look at the source code of Signonterceptor, which is originally given to signon.jsp gives a signonforwardaction object, huh, huh, finally understand. 3). Next to learn Signontroller, it can be seen in its main part. First take the user input UserName and Password, and then verify that this user is verified in the database. If there is no user, return each error page; if successful, First become a UserSession object, join this UserSession in Request's session, pay attention to this part of the code, the simple usage method of the PagedListholder paging, about the paging display, after learning. 3. After the login is successful, you can obtain different behaviors according to different user facilities, and user information is obtained, nothing more than the useersession from Session.

转载请注明原文地址:https://www.9cbs.com/read-17362.html

New Post(0)