1. Download eclipse
Log on to the eclipse official website to download http://www.eclipse.org/downloads/
I chose eclipse classic 3.6.2, 32-bit
2. Add web and Java EE development tools
Help-> install new software, select "Helios-http://download.eclipse.org/releases/helios" in the "Work with:" drop-down box (if not, you can add it yourself), and then in "Web, XML, and java EE development "select
-Eclipse Java EE Developer Tools
-Eclipse Web Developer Tools
-JST server adapters (required to create Apache Tomcat server)
3. Download Tomcat
Log on to Apache Tomcat official website to download http://tomcat.apache.org/
I chose Tomcat 7.0.14.
4. Add Tomcat plug-in
Http://www.eclipsetotale.com/tomcatPlugin.html
It seems that there is no official website or update site.
Download the package, decompress it, copy it to the plugin directory, and restart eclips.
5. Create a WEB Project
File-> New-> Project-> dynamic web project
6. Add the struts 2 class library
Login struts official website download http://struts.apache.org/downloads.html
I chose struts-2.2.3-lib.zip.
Download and decompress, copy the core class library required by struts 2 to the webcontent/WEB-INF/lib of the web Project
Commons-fileupload-1.2.2.jar
Commons-io-2.0.1.jar
Commons-lang-2.5.jar
Commons-logging-1.1.1.jar
Freemarker-2.3.16.jar
Javassist-3.11.0.GA.jar
Ognl-3.0.1.jar
Struts-core-1.3.10.jar
Xwork-core-2.2.3.jar
7. Create web. xml
I don't know why, there is no web. xml when the project is created, but it doesn't matter. We can build it ourselves.
File Location:/webcontent/WEB-INF/Web. xml
Content XML Code
- <? XML version = "1.0" encoding = "UTF-8"?>
- <Web-app id = "webapp_id" 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">
- <Display-Name> project name </display-Name>
- <Welcome-file-List>
- <Welcome-File> index.html </welcome-File>
- </Welcome-file-List>
- <Filter>
- <Filter-Name> struts2 </filter-Name>
- <Filter-class> org. Apache. struts2.dispatcher. filterdispatcher </filter-class>
- </Filter>
- <Filter-mapping>
- <Filter-Name> struts2 </filter-Name>
- <URL-pattern>/* </url-pattern>
- </Filter-mapping>
- </Web-app>
<? XML version = "1.0" encoding = "UTF-8"?> <Web-app id = "webapp_id" 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"> <display-Name> project name </display-Name> <welcome-file-List> <welcome-File> index.html </welcome-File> </welcome-file-List> <filter-Name> struts2 </filter-Name> <filter-class> Org. apache. struts2.dispatcher. filterdispatcher </filter-class> </filter> <filter-mapping> <filter-Name> struts2 </filter-Name> <URL-pattern>/* </url-Pattern> </filter-mapping> </Web-app>
8. Create struts. xml
File Location:/webcontent/WEB-INF/Classes/Struts. xml
Content XML Code
- <? 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>
- <Package name = "default" extends = "struts-Default">
- <Action name = "action_name" class = "package_name.class_name">
- <Result name = "success">./WEB-INF/JSP/success. jsp </result>
- <Result name = "failure">./WEB-INF/JSP/failure. jsp </result>
- </Action>
- </Package>
- </Struts>
<? 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> <package name = "default" extends = "struts-Default "> <action name =" action_name "class =" package_name.class_name "> <result name =" success ">. /WEB-INF/JSP/success. JSP </result> <result name = "failure">. /WEB-INF/JSP/failure. JSP </result> </Action> </package> </struts>
9. Create a server
File-> New-> Server
"Server type" I selected "Tomcat v7.0 server" and moved the new web project to "configured ".
In this way, the structure of struts 2 is basically set up.