The configuration installation struts2.0 needs to be divided into several steps:
First step: Open the http://struts.apache.org/download.cgi address, download the latest struts2.0.
Step two: Copy all jar files in Lib struts2.0 to the/web-inf/lib directory in WebProject project.
The third step: the download from the struts2.0 directory to find Struts.xml and struts.properties into the WebProject Project SRC directory, through the MyEclipse compiled this two files will be compiled to/web-inf/ The classes directory.
Contents of Struts.xml File:
<?xml version= "1.0" encoding= "UTF-8"?>
<! DOCTYPE Struts Public
"-//apache Software foundation//dtd Struts Configuration 2.0//en"
"Http://struts.apache.org/dtds/struts-2.0.dtd" >
<struts>
<constant name= "Struts.enable.DynamicMethodInvocation" value= "false"/>
<constant name= "Struts.devmode" value= "false"/>
<!--
<package name= "Person" extends= "Struts-default" >
<action name= "List" method= "Execute" class= "Personaction" >
<result>pages/list.jsp</result>
<result name= "Input" >pages/list.jsp</result>
</action>
</package>-->
</struts>
Configuration in Struts.properties file:
Struts.devmode = False (specifies that struts2 is in the development State)
Struts.configuration.xml.reload = True (Specifies whether the Web frame reloads the struts2 configuration file after the Struts2 configuration file is changed)
Step Fourth: Create a new Applicationcontext.xml file in the Web-inf directory.
The contents of the Applicationcontext.xml file are as follows:
<?xml version= "1.0" encoding= "UTF-8"?>
<! DOCTYPE beans Public "-//spring//dtd bean//en" "Http://www.springframework.org/dtd/spring-beans.dtd" >
<beans default-autowire= "AutoDetect" >
</beans>
Fifth step: In the download of the struts2.0 file to find Log4j.jar package, placed in the/web-inf/lib directory.
Step Sixth: Configure the Web.xml file
<?xml version= "1.0" encoding= "UTF-8"?>
<web-app version= "2.4" xmlns= "HTTP://JAVA.SUN.COM/XML/NS/J2EE"
Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" xsi:schemalocation= "Http://java.sun.com/xml/ns/j2ee http:/ /java.sun.com/xml/ns/j2ee/web-app_2_4.xsd ">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/classes/applicationContext-*.xml</param-value>
</context-param>
<filter>
<description>struts2</description>
<filter-name>struct2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>struct2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>3</param-value>
</init-param>
<init-param>
<param-name>detail</param-name>
<param-value>3</param-value>
</init-param>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
If you add a JSP file (if you need a Struts2 tag in your JSP page, just introduce it to the JSP page), you don't need to configure the code in the Web.xml file
<%@ taglib prefix= "s" uri= "/struts-tags"%>
<jsp-config>
<taglib>
<taglib-uri>/s</taglib-uri>
<taglib-location>/WEB-INF/struts-html.tld</taglib-location>
</taglib>
</jsp-config>
<login-config>
<auth-method>BASIC</auth-method>
</login-config>
</web-app>
Step Seventh: Run the program
About the struts2.0 directory description:
Apps: This folder contains sample applications based on struts2, which are useful for learners.
Docs: This folder contains strut2.0 documentation, including Strut2 QuickStart, Struts2 QuickStart, STRUCT2 documentation, and API documentation.
J4: This folder contains the jar packs that allow struts2 to support JDK1.4
Lib: This folder contains the core class libraries of the STRUTS2 framework, as well as the Struts2 Third-party plug-in class library.
SRC: This folder contains all the source code for the STRUTS2 framework.