**Struts2** as a development framework, it provides us with a good development template, using **Struts2** can reduce the burden of developers and can enhance the readability of the program, here is how to use **Struts2** to do a small example:

Development tools/development environment needed: [1] Struts2 development JAR package [2] a struts.xml document template [3] Java development IDE– MyEclipse

Development is accomplished in the following four steps: [1] Import the corresponding JAR package [2] Configure the Struts core filter in the web.xml document [3] Create the required Action [4] Configure the Action in the struts.xml document [5] Create the corresponding use JSP file

Below regarding the above five steps in detail: 【 1 】 I arrange for you the struts 2 the jar package development need, you can download it in this link: link: http://pan.baidu.com/s/1i5QRs01 password: gmik. After downloading these JARs, import them into the lib directory under Webroot

[2] As for Struts2 core filter configuration, two attributes need to be configured, one is filter, and the other is filter-mapping, that is, image configuration of filter. The specific configuration is as follows:

<filter>
      <filter-name>Struts</filter-name>
      <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteF
    ilter</filter-class>

</filter>

<filter-mapping>

      <filter-name>Struts</filter-name>
      <url-pattern>/*</url-pattern>

</filter-mapping>

[3] Creating an Action is essentially creating a Java class that handles the logic, such as the Action in this example:

public class HelloWorldAction extends ActionSupport { @Override public String execute() throws Exception { // TODO Auto-generated method stub //return super.execute(); System. The out. Println (" executive action "); return SUCCESS; }} This Action is executed by printing "Execute Action" to the console when the Action is executed.

[4] Configure the action in the struts.xml document, essentially telling the page how to use the action. The configuration is as follows:

<struts>
<package name="default" namespace="/" extends="struts-default">
    <action name="helloworld" class="Action.HelloWorldAction">
        <result>/result.jsp</result>
    </action>
</package>
</struts>

[5] The key to using Action in JSP pages is to fill in the path. For example, the value of the HREF attribute in the A tag is the value of the name in the Action file in the struts.xml file. This is a process for getting started in Struts2. If you still have questions after watching it, you can pay attention to my WeChat public account to consult me. Please kindly check the QR code below scan:

! [Photo description][1]

Below is the entire project file package: link: http://pan.baidu.com/s/1nuEXCCh password: t0yj