STRUTS2 Overview, development environment Construction

Source: Internet
Author: User

I. Overview

Struts 2 was developed on the basis of WEBWORK2. As with Struts1, it belongs to the MVC framework.

Note: Struts 2 and struts 1 are almost different in code style.

Struts 2 has advantages over struts 1:

1. In software design, struts 2 is not tightly coupled with the Servlet API and struts API as struts 1 does. Struts 2 applications can be independent of the Servlet API and the Struts API. The STRUTS2 design is non-intrusive and struts1 is an intrusive design.

2. Struts 2 provides interceptors that can be programmed with an AOP using interceptors.

3, Struts 2 provides a type converter. We can convert special request parameters into the desired type. In Struts1, if we are to implement the same functionality, we must beanutil register the type converter to Struts1 's underlying implementation.

4, Struts 2 provides support for a variety of performance layer technology, such as: JSP, freemarker, velocity and so on.

5, the input check of Struts 2 can be specified method for verification.

6, Struts 2 provides global scope, package scope and action scope of Internationalized resource file management implementation.

Second, STRUTS2 system structure

1. Web browser requests a resource.

2, Filter Dispatcher Find method, determine the appropriate action.

3, interceptors automatically apply common functions to the request, such as verification and file upload operations.

4. The Execute method of action is usually used to store and re-obtain information.

5. The result is returned to the browser.

Third, build Struts 2 development environment

  

1. Find the jar package needed to develop the application for Struts 2.

A) to http://struts.apache.org/download.cgi#struts221 download Struts-2.5-all.zip, unzip the file after download, development STRUTS2 application needs to rely on the jar file in the directory to extract the Lib folder. Different applications require a different jar package.

b) Develop the minimum required jar for the STRUTS2 program:

Core class Library of Struts-core-2.x.x.jar:struts 2 framework

Xwork-2.x.x.jar:xwork class Library, Struts 2 builds on it

Ognl-2.6.x.jar: Object graph Navigation Language (objects Graph Navigation Language), Struts 2 framework through the properties of its read-write object

Templates for UI labels for freemarker-2.3.x.jar:struts 2 are written using Freemarker.

COMMONS-LOGGING-1.1.X.JAR:ASF produced by the journal package. The STRUTS2 framework uses this log package to support log4j and jdk1.4+ log records

Commons-fileupload-1.2.1.jar: File Upload Component, 2.1.6 after version must be added to this file

2, write the configuration file of Struts 2.

Struts2 default configuration file is Struts.xml, the file needs to be stored under web-inf/classes, the development phase can be placed in the SRC directory. The configuration template for this file is as follows:

1 <?xml version= "1.0" encoding= "UTF-8"?>2 <! DOCTYPE Struts public 3         " -//apache software foundation//dtd Struts Configuration 2.3//en "4         " http://struts.apache.org/dtds/ Struts-2.3.dtd ">5 <struts>6 </struts>

3. Join the Struts 2 MVC boot Framework configuration in Web. Xml.

In struts1.x, the Struts framework is initiated by the servlet. In Struts2, the struts framework is started by using filter. It is configured in Web. Xml as follows:

<filter>        <filter-name>struts2</filter-name>        <filter-class> Org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter </filter-class><!-- Since struts2.1.3, the following filterdispatcher have been marked as obsolete <filter-class>org. Apache. Struts2.dispatcher.filterdispatcher</filter-class>>--></filter><filter-mapping>        <filter-name>struts2</filter-name>        <url-pattern>/*</url-pattern></ Filter-mapping>

The init () method in Strutsprepareandexecutefilter will read the default configuration file under the Classpath struts.xml complete the initialization operation.

Note: After struts2 reads the contents of Struts2.xml, it is stored in memory in JavaBean form, and struts2 each request processing of the user will use the data in memory instead of reading the Struts.xml file every time.

STRUTS2 Overview, development environment Construction

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.