Struts2 Based on the ssh (sturts2_spring_hibernate) framework and sturts2 configuration in ssh integration

Source: Internet
Author: User
Tags custom name

Struts2 Based on the ssh (sturts2_spring_hibernate) framework and sturts2 configuration in ssh integration

 

 

        

I. Logic of struts2 complete process (overall overview)

First, the user enters the access path of your project in the address bar, and then the request is sent to the server, and then the server finds it in the web. A filter is configured in xml, and the filter needs to filter all access requests. In struts construction, you must first configure a filter, therefore, we can regard this struts as a filter. All user requests must be allocated through struts. After the server receives the user request, it will send the request to struts. The specific processing relies on the class configured in the web. xml. We do not understand how to handle it. Then accept the user's request, struts. xml for processing. The name attribute in the action tag is the specified name entered when the user accesses your project. However, the class attribute defines the class to be processed for this name request, that is, the action class, method specifies a method in this class. Then call this method. Then, return a value, and specify in struts. xml to jump to the page based on the returned string.

The details are as follows:

      

Ii. struts2 Construction

1. Import related jar packages:

①: Download struts2 from the official website. Official download: http://struts.apache.org/download.cgi?struts252,select the desired region.

②: After decompression, find the folder lib. Only the following package needs to be imported into your project:

    

 

2. web. xml configuration file:

① Configure the filter used by struts2 and use org. apache. struts2.dispatcher. ng. filter. StrutsPrepareAndExecuteFilter as the processing class (filter-class ).

② Specific statement:

3. struts. xml configuration file:

① Create an xml file in the src directory, that is, the struts. xml configuration file.

② Declare the dtd specification at the top of the configuration file of struts2.xml, that is, document type definition, as follows:

    

③ Configure the struts2 environment:

Specific statement:

(1) define a package tag in the struts tag and set the attributes of name and extends. The attribute value of name is the custom name, and the value of extends must be "struts-defaul ";

(2) define an action tag in the package tag and set the attribute name, class, and method;

The name attribute sets the path name for accessing the project in the URL; the class sets the class for business logic processing (package name. class name );

The method property is set to the specified method in the class to be accessed (write the method name). If the value of the method property is not set, execute () is called by default ().

(3) define the result tag in the action tag and set the name attribute;

The property value is the return value of the method in the method attribute of the action tag (the return values of these methods are String );

Result labels are the pages to jump.

The details are as follows:

            

      

 

 

 

4. action Processing

1. Define a class and inherit from ActionSupport. In this method, define some member variables and methods;

(1. member variables are generally used to save data or to wait for the instance to be injected (when spring and struts2 are used in combination, the method of the instance to be injected with properties is used ), the data stored in the member variables can be the parameters passed by the user request or the set and information obtained from the database curd.

(2) The return values of the methods defined in this class are of the String type. The returned String matches the configuration in struts2.xml.

  

Iii. Summary of struts2:

(1) is a framework for web application development, essentially equivalent to a servlet.

(2) struts2 is a combination of webwork2 and struts1 developed by opensymphony. Struts1 is further improved based on model2 (MVC.

(3) struts2 does not need to manually write and obtain parameters (you need to set an attribute and set the getter and setter methods). You do not need to manually write the jump code (in struts. xml configuration file), and converts the attribute types in the database and JAVA classes.

(4) Subcontracting in struts:

① Action package: page Jump and parameter transfer and receipt.

② Services package: business logic processing. For example, you need to further judge the user registration duration for the data obtained from the database.

③ Dao package: perform database curd operations. However, no further operations are performed on the data.

④ Entity package: stores entity classes.

⑤ Util package: Toolkit, for example, database connection.

Related Article

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.