First, Struts's origin Struts was earliered as part of the Apache Jakarta project, and the founders of the project hoped to improve and improve the JavaServer Pages, Servlet, label libraries, and object-oriented technology. Struts This name is from the support metal rack used in the building and the old aircraft. The reason why this frame is called "Struts", in order to remind us to remember the basic support of our housing, architecture, bridge, and even we step on stories. This is also a wonderful description of the role that Struts played in the development web application. When establishing a physical building, construction engineers use the pillars to support each layer of the building. Similarly, software engineers use Struts to support each layer of business applications. Its purpose is to help us reduce the time to develop web applications with the MVC design model. We still need to learn and apply this architecture, but it will be able to complete some of these heavy work. If you want to mix the advantages of servlets and JSP to establish scalable applications, Struts is a nice choice. Early SmallTalk programming uses the MVC-View -Controller mode (Patterns) to add program code elasticity, MVC mode cuts the program code to three, and the Model section is the business and application domain related logic. The object of the management status, the Controller section receives the information entered from the View and interacts with the Model part. It is a business process control (Flow Control), and the View section is responsible for displaying the information and receives the user input information. In Java applications, JFC / Swing, AWT, JSP are available as a technical specifications that can be used as a View, while JavaBean and Enterprise JavaBean specification can be used for Model program code, once the application is appropriately split by MVC mode, MODEL section program code Use in applications where different user interface appearance is repeated. As JSP and Servlet technology is applied to web-based applications, Java developers believe that the maintenanceability and repetition of Web applications should be improved in better patterns. Early JSP specifications have enumerated two feasible JSP application architectures, respectively, named Model1 and Model 2. In the Model 1 architecture, JSP processes requests from the web browser, and assists in the JavaBean processing application related logic. The Model 1 architecture is simple to write, but JSP in Model 1 may shoulder the View and Controller roles, and the two types of program code may be mixed without maintenance. The servlet is included in the architecture to play the front-end controller role in Model 2, and send the request to the web browser to servlet, and servlet can centrally manage the user login, permission control, multi-language conversion, etc., and then turn to demand Corresponding JSP processing. The MODEL 2 adopts better MVC mode, but has added complexity of writing. Struts is part of the Jakarta project under the Apache Software Fund. In addition to Struts, there are other successful open source products, including Tomcat, Ant and Velocity. In 2000, Craig R. Mr. McClanahan contributed the Application Framework original program code for JSP Model 2 in which he wrote to the Apache Foundation, became the Apache Jakarta Planning Struts Framework. The starting code foundation has been developed from May 2000 until June 2001, version 1.0 released.
More than 30 developers participated in and thousands of people participated in the discussion group. The STRUTS code is managed by a volunteer Commnitter team. By 2002, the Struts Group has 9 volunteer commnitter. The main architectural design and developers of the Struts framework are Craig R. McClanahan. Craig is also the main architect of Tomcat 4, as well as major architects and implementors of Java Web Services Developer Pack. He is now the SUN JavaServer Faces (JSR-127), and the Normal Leaders of the web layer architecture of the J2EE platform. Mr. Craig R. Mr. McClanahan is one of the members of JCP ExpertGroup. He has participated in the JSP specification to prepare with Tomcat 4, so Struts Framework is widely attached importance to Java developers. Borland has supported Struts framework in the development tool JBuilder at the end of 2002. Second, Struts Installation 1, install the software Java Development Kit, which is required to install Struts - we need Download and Install 1.2 (or after) version of JDK. Download address: http://java.sun.com/j2se servlet container - The usual selection is to download Tomcat (at least version 3.1, recommended version of 4.0 or more). Download address: http://jakarta.apache.org/tomcat Ant Build System - If we install the package through the Struts source code package, we must download the 1.1 or later version of the Ant Build System. Developing our own web apps through Struts is, it is recommended to use Ant to Build our app. Download address: http://jakarta.apache.org/ant servlet API Classes - To compile Structs yourself, or the application uses Struts, we need a servlet.jar package that contains the servlet and JSP API objects. Most servlet containers (such as Tomcat) have come with this file. Otherwise, we must download: http://jakarta.apache.org/builds/jakarta-servletapi XML Parser - Structs requires an XML processor compatible with Java API for XML Parsing (JAXP) specifications, we can use Xerces. Download address: http://xml.apache.org/xerces-j Xalan XSLT Processor - If we construct our Structs system via the STRUCTS source code, we must download and install 1_2_d01 or later Xalan XSLT processors ( This is coming from Xerces. This processor is used to convert XML-based Structs documents to HTML documents. 2, through the Source Code Construction Structs 1) Download the StruCTS source code release package. 2) Set an ANT_HOME environment variable to point to our Ant directory. 3) Set the java_home environment variable, point to our JDK directory. 4) Set the servletAPI_HOME environment variable, point to our servlet API directory (if our ClassPath already contains servlet.jar, you do not need to specify the directory) 5) Unpack the StruCTS source code package.
6) Go to the STRUCTS directory, run the following command: ./build.sh Dist This command will create a Struts binary package, directory in ../ dist / structs (relative to our compilation directory). 3. Install Struts 1) Download the Struts binary release. 2) Unread the Struts binary release. (If we construct Struts through the Struts source code, the result of Build is already unpacked Struts). Unpacking Struts contains the following: lib / struts.jar - This file contains all Java objects for Struts. We need to copy it to our web-INF / lib directory for our web application. LIB / STRUCTS.TLD - This is a "Tag Library Descriptor" file that describes the free TAG of the Struts library. Need to copy it to our web-inf directory for our web application. WebApps / Struts-Documentation.war - This is a "Web Application Archive" file that contains all Struts documents. We can install it to the servlet container that supports Servlet API 2.2 or later (recommended using Tomcat). WebAPPS / Struts-Example.war - This is a web application instance that extensively demonstrates many of the Struts. We can install it into a servlet container that is compatible with servlet2.2 or later and the JSP1.1 or later version of the servlet container (recommended using Tomcat). WebApps / Struts-Test.war - This web application contains many TAG test web pages supported by Struts, which can be used as an example of using Struts Tag. 4, Struts's basic component package installed Struts has approximately 15 packs, nearly 200 classes, and quantity is still expanding. Here we cannot introduce one by one, only to list several major brief introductions. The following table describes several component packages in the current Struts API, including Action, Actions, Config, Util, Taglib, Validator. As shown in Table 1 below: Org.apache.struts.Action basically, control the core class of the running of the entire Struts Framework, the components are in this package, such as the controller ActionServlet we mentioned above. Action, ActionForm, ActionMapping, etc. Struts1.1 is more than 1.0 DynaActionform class. Added Dynamic Extension Generation FormBean Features Org.Apache.Struts.Actions This package is the primary role to provide a specific adapter conversion function between the client's HTTP request and business logic processing, and some of the part of the version 1.0 reproduces the class of frombean, The DynaActionForm component replaced by the ACTION package in Struts1.1 provides mapping of the configuration file struts-config.xml element. This is also a new function in StURTS1.1 org.apache.struts.util Strtuts to better support Web Application's application, such as support, such as Connection Pool and Message Source. For more information, please refer to http://jakarta.apache.org/struts/api/rg/apache/struts/util/package-summary.html org.apache.struts.taglib This is not a package, but a customer label class Collection.
The following includes Bean Tags, HTML Tags, Logic Tags, Nested Tags, Template Tags, for building tag classes for building user interfaces. Org.apache.struts.validator struts 1.1 Framework adds Validator Framework for dynamic configuration of the FROM form. For more information, see http://home.earthLink.Net/~dwinterfeldt/ 3, Struts Configuration and Component Description About struts Components Configuration Struts-Config.xml file Descriptions have been introduced in front of the article, this is no longer said, The components and configurations in the framework are mainly introduced. The following table lists the core class of Struts, that is, the corresponding classic MVC component duties. Table 2 Core Struts Class and MVC Correspondence Class Description ActionForward User Points or View Select ActionMApping Status Change The ActionMApping Status Change Event ActionServlet controller, accept user request and status change, and send a view to select a part of the Action controller, in the model interaction , Execution status change or status query, and tell the ActionServlet Next selected view In addition to these core classes, Struts uses some profiles and view helpers to communicate controllers and models. The following table lists the Struts profile and describes the roles they in the architecture. Table 3 STRTUTS Profile File Destination ApplicationResources.properties Stores localized information and labels to enable applications to international Struts-Config.xml storage controller object default configuration, including model supported by users, state changes, status query Exposing the Struts configuration data to the view, the frame provides a large number of assistant classes in the form of a JSP tag, as Table 4 STRTUS View Assistant. Tag Library Descriptor Struts-HTML.TLD Extended HTML Form's JSP Tag Struts-Bean.TLD Extension Processing JavaBean JSP Tag Struts-Logic.TLD Extended Test Property JSP Tag Controller Component's Configuration Framework Controller Components There is an org.apache.struts.Action.ActionServlet class implementation, this class is an extension of the javax.servlet.http.httpservlet class. ActionServlet configuration: We need to declare an actionServlet in Web.xml, and load it to start.
The following is an initialization parameter that can be configured: parameter default value Description Application Null application resource collection class buffersize 4096 file upload buffer size config /web-inf/struts-config.xml configuration file location and name Content Text / HTML Deflicit content type Debug 0 Program debugging level Detail 0 Program debugging detail level Factory Null message resource factory, 馐 ⒆ ⒆ ⒆ ⒆????? ⒆ ⒆ 馐 馐 馐 馐 ⒆ ⒆ 馐 馐 馐 馐 馐 馐 馐The name of the class of bean information forward org.apache.struts.Action.ActionForward package ActionForward object information class Locale true is true, will store a local object mapping org.apache.struts.Action.ActionForward encapsulation amapping in a user session The name of the information class MaxFileSize 250M Upload file Maximum size MULTIPARTCLASS org.apache.struts.Action.ActionForward Processes the NOCACHE FALSE HTTP header to be set to True, for invalidation Information Keywords Returns NULL TEMPDIR as a servlet parameter to provide the program Work directory processing download file is the temporary work directory VALIDATE TRUE uses the new format VALLIDATING TRUE to effectively analyze the profile to analyze the configuration files Most cases The standard servlet can meet the needs of users. When the URI of the first received a specific request, the ActionServlet instantiates the appropriate Action class, and the ActionServlet stores a reference in servlet in the Action class instance. When instantiated, the Action class will be temporarily stored. Error Handling Struts provides two classes to handle errors: ActionerRRORS and ActionError, they all expand org.apache.struts.Action. ActionerRORS saves a collection of ActionError objects, each represents an independent error message. Each ActionError contains a keyword, which is mapped to the error message stored in the resource file, and this resource file is specified in the ActionServlet initialization parameter. Fourth, Struts runs with the following steps to use Struts: 1 in our own application, copy the Struts directory lib / struts.jar to the web-inf / lib directory of the web application. 2. Copy the lib / struts * .tld of the struts directory to the web-inflicity of the web application. 3, modify the web-inf / web.xml file of the web application directory, add a
4. Modify the web-inf / web.xml file for the web application directory so that the following Tag library definition: