A small module case of the JPA Project

Source: Internet
Author: User
Tags tld

Recently, I was working on a web project. I found a small module to take notes and sorted it out a little. Well, I entered the question.

The framework used in the entire project is roughly as follows: backend> STRUTS + spring + JPA;

Foreground> jggrid

The following is the background function logic of the entire project:


The following section shows the front-end page:


This is the jar package used by the system:


Because struts labels are used, you need to introduce the file (the path is above ):

1, B/webroot/WEB-INF/struts-bean.tld

2, B/webroot/WEB-INF/struts-html.tld

3, B/webroot/WEB-INF/struts-logic.tld

The configuration files mainly include:

1. B/src/META-INF/persistence. xml

2. B/src/log4j. Properties

3. B/src/Save. Properties

4. B/webroot/WEB-INF/applicationcontext. xml

5. B/webroot/WEB-INF/config. Properties

6, B/webroot/WEB-INF/Struts-config

7. B/webroot/WEB-INF/Web. xml

 

The following describes the logon page in sequence:

First, the system automatically loads the index. jsp page with the following content:


The login. jsp page is automatically displayed.

Part of login. jsp:


Most formats are defined using the style label on the logon interface. The script defines the function functions responded by some buttons.

In addition, the front-end page mainly defines a form that communicates with the background. After you enter the user name and password, click the login button. First of all, check whether the entered information is empty through Script script, if this parameter is not blank, the username and password parameters in form are submitted to the specified background action in the form tag through the function.

 

Next, I will explain how to find the corresponding action.

Here we need to use the configuration file struts-config.xml mentioned above, its general content is as follows:


Because the front-end is from login. the parameters passed by JSP and the parameters passed to loginaction are specified in the foreground. In this configuration file, we can easily find the background Java file corresponding to this action, that is, Com. the loginaction Java file in Package B.

Then we can go to the loginaction. Java file to check whether a myproperties class object is created.

1. In this class, the loadproperties () method is called first. Go to this method and check it. This method first sets the configuration file config. the content in the properties file is read to the input stream and then loaded to the properties defined in the file. Then, the corresponding value is found based on the name of the properties file and assigned to the system.

2. After loading, assign the connection. jndi_name, connection. usepool, and connection. User values to the database connection pool.

Request. getparameter () obtains the USERNAME \ password parameter from the front-end, and then finds that a Class Object of loginuser is created, and the ID of this object is assigned a null value (why is it set to null here, later), and through the request. getremoteaddr () gets the author's IP and assigns a value to this object.

1. Let's take a look at what is in the loginuser class:

It defines some attributes of a user: User Name, user ID, user password, and the corresponding get \ set method.

Looking down, we found that another userbo class object was created and the setloginuser method of the class was called.

1. Let's take a look at the userbo class:

This class first creates a database connection pool instance, uses the bean> id = "datasource" in the previous configuration file applicationcontext. XML to read the corresponding information.

2. Call the setloginuser method, call the getconnection method in connectionpool, and return the previously established database connection.

3. The setloginuser method creates another userdao object and then calls the setloginuser method of userdao. This method begins to write SQL statements to obtain information about the current user and assign values to the loginuser object.

Return to loginaction. in Java, if is determined, and if the ID is still empty, then you need to log on again, because if the login is successful, the setloginuser method of userdao has obtained the ID, this should not be empty. If the logon succeeds, call the loginuserspring object created by loginuser of COM. B. System. VO through springutils.

Then, use request. getsession (). setattribute () to assign some attributes of loginuser to the request.

After these operations are completed, that is, after logging on to and passing authentication, and return success.

Next it's time to view the struts-config.xml page and jump to the welcome. jsp page when forward = "success.

The preceding flowchart is as follows:

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.