在Eclipse Helios 3.6.2下配置Struts2开发环境

在Eclipse Helios 3.6.2上配置Struts2开发环境
1. 下载Eclipse
登录Eclipse官网下载http://www.eclipse.org/downloads/
我选择的是Eclipse Classic 3.6.2, 32位

2. 添加Web and Java EE开发工具
Help -> Install new software,在"Work with:"下拉框中选中"Helios - http://download.eclipse.org/releases/helios"(如果没有,可以自行添加),然后在"Web, XML, and Java EE Development"中选择
  - Eclipse Java EE Developer Tools
  - Eclipse Web Developer Tools
  - JST Server Adapters (创建Apache Tomcat Server需要)

3. 下载Tomcat
登录Apache Tomcat官网下载http://tomcat.apache.org/
我选择的是Tomcat 7.0.14

4. 添加Tomcat插件
http://www.eclipsetotale.com/tomcatPlugin.html
这个好像没有官网,也没有update site
下载后解压,复制到plugin目录下,然后重启eclips即可

5. 创建Web工程
File -> New -> Project -> Dynamic Web Project

6. 添加Struts 2类库
登录Struts官网下载http://struts.apache.org/downloads.html
我选择的是struts-2.2.3-lib.zip
下载后解压,把Struts 2必须的核心类库复制到到Web工程的WebContent/WEB-INF/lib下
  - 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. 新建web.xml
不知道为什么,工程创建的时候没有web.xml,不过没有关系,我们可以自己建
文件位置:/WebContent/WEB-INF/web.xml
内容
<?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>


8. 新建struts.xml
文件位置:/WebContent/WEB-INF/classes/struts.xml
内容
<?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. 创建Server
File -> New -> Server
"Server Type"我选择了"Tomcat v7.0 Server",然后把新建的Web工程移动到"Configured"中就可以了

这样基本就搭建好Struts 2的结构了