1. Create a new Java Web project in eclipse
2. Copy Jar Package
In the downloaded struts2, there is an Apps folder, and the. war file in this folder is an official example, where Struts2-blank.war is an empty application, that is, nothing inside. But this is not the least.
Unzip the Struts2-blank.war and copy the. jar file under Struts2-blank\web-inf\lib to the Lib folder in the Java WEB Project.
3. Configure the Web. xml file
Copy the configuration code for Fileter in the Web. XML in Struts2-blank to the website. XML for the Java project, my web. xml file is as follows:
<?xml version= "1.0" encoding= "UTF-8"? ><web-app xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" xmlns= "Http://java.sun.com/xml/ns/javaee" xsi:schemalocation= "Http://java.sun.com/xml/ns/javaee/http Java.sun.com/xml/ns/javaee/web-app_2_5.xsd "id=" webapp_id "version=" 2.5 "><display-name>struts2-2</ display-name><!--Configuration struts2 Filter-<filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern> /*</url-pattern> </filter-mapping> <welcome-file-list><welcome-file>index.html</welco Me-file><welcome-file>index.htm</welcome-file><welcome-file>index.jsp</welcome-file ><welcome-file>default.html</welcome-file><welcome-file>default.htm</welcome-file><welcome-file>default.jsp</welcome-file></welcome-file-list></ Web-app>
The meaning of this configuration is:
All requests are to be intercepted by Strutsprepareandexecutefilter.
4. Add struts-2 configuration file
Copy the Struts2.xml file under the struts2-blank\web-inf\classes directory to SRC. You can delete extra items, leaving only the struts root node.
5. Tips for adding struts.xml
Copy struts2.xml in: HTTP://STRUTS.APACHE.ORG/DTDS/STRUTS-2.3.DTD
Windows->preferences->xml->xml Catalog
Click Add to copy it to the text box after key, key type select URL,
Click File System, add Struts-2.3.dtd, located at: struts-2.3.16.3\src\core\src\main\resources
:
Ok
To turn struts.xml back on, you can see the prompt:
--struts2--2--Building STRUTS2 Environment in open class of Silicon Valley