Struts2 (1)-learn about Struts2 & amp; configure the Basic Environment

Source: Internet
Author: User

Struts2 is a free and open-source MVC framework provided by Apache for compiling elegant and modern Java web applications. Struts emphasizes that conventions are better than configurations. It is very easy to expand using the plug-in architecture, and some plug-ins support REST, AJAX, and JSON. Struts2 is developed based on WebWork2. Although the names of Struts2 and Struts1 are not very different, the coding styles of Struts2 and Struts1 are almost different. Now that we have Struts1, why should we release Struts2? The answer is, of course, Struts2 has the following advantages: 1) in software design, Struts2 is not closely coupled with Servlet APIs and Struts APIs as Struts1 does, struts2 applications can be independent of Servlet APIs and Struts APIs ., Struts1 is an intrusive design. 2) Struts2 provides an interceptor that can be programmed with AOP to implement functions such as permission interception. 3) Struts2 provides a type converter. We can convert special request parameters to the desired type. In Struts1, if we need to implement the same function, we must register the type converter with the underlying implementation of BeanUtil in Struts1. 4) Struts2 supports multiple presentation layer technologies, such as JSP, freeMarker, and Velocity. 5) The Struts2 input validation can be performed to solve the long-term pain of Struts1. 6) provides global resource file management, including global resource file scope, package scope, and Action Scope.2.1 Download The Struts2 file (http://struts.apache.org/) from the Apache official website /). PS: The downloaded file is struts-2.3.8-all.zip. 2.2 struts-2.x.x unzip contains 4 folders, detailed introduction: 2.2.1 apps: Struts2 some examples, can be deployed in the application server for testing 2.2.2 docs: Struts2 all help documentation () 2.2.3 lib: contains all jar packages of Struts2 and required third-party jar packages 2.2.4 src: source code 2.3 Development Environment 2.3.1 IDE: SpringSource Tool Suite2.9.2 (STS) 2.3.2 Application Server: Tomcat 7.xThe basic steps for configuring the Struts2 environment are as follows: (1) Find the jar file required for developing the struts2 application (2) Compile the struts configuration file of struts2. xml (3) in the web. below is the startup configuration added to the Struts2 MVC Framework in xml, a JAR package is provided for the development of the Struts2 program.
Take my Struts2.3.8 as an example. In addition, you can obtain the lib package directly from the struts-blank project under the apps folder (a few more packages will be obtained ).. PS: Enter the src folder in the development phase. The format of struts. xml is as follows (this template can also be found in the struts-blank project ):

 

< strong>. The configuration is as follows:
Struts2 org. apache. struts2.dispatcher. ng. filter. StrutsPrepareAndExecuteFilter struts2 /*

 

After completing the preceding three steps, start the Tomcat server. If no error occurs during normal startup, the Environment configuration of Struts2 is successful. If the configuration fails, you need to carefully check each step and find the problem.
After configuring the Struts2 environment, you need to compile a simple Demo to test Struts2. Of course, at this time, we will be playing HelloWorld forever. The entire process is also completed in three steps. (1) Compile the corresponding Action-HelloWorldAction (2) Configure HelloWorldAction in struts. xml (3) Compile the JSP page corresponding to the forwarding View < strong>
 
      /WEB-INF/page/message.jsp   

 

< strong>. Create a folder page under the WEB-INF folder and generate a JSP page. Then, add $ {message} between the <body> labels to print the message Value in the Action.
       Struts2 Demo     
In the browser, enter "http: // localhost: 8081/Struts2Test/harryyu/helloworld" to see the following results. So far, the first Demo program based on Struts2 has been completed. The next article will introduce the relevant content of Action and the configuration parameters of the action tag in struts. xml. Bye everyone ~

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.