01_1_Struts环境搭建
1. MyEclipse配置部分
1.1创建项目
新建new—>Project—>Web Project—>Project Name(配置项目名)—>J2EE Specification Level(勾选Java EE 5.0)—>Finish—>Incompatible Java Compliance Level(点击Yes)
1.2配置容器
Windows—>Preferences—>MyEclipse—>Servers—>Tomcat—>Tomcat 7.x(选择Enable,并配置Tomcat相应路径,此处略)
1.3配置JREs
Windows—>Preferences—>Java—>Installed JRES—>Add—>Standard VM(Next)—>配置相应的JRE路径,此处略
2. Struts相应配置
2.1下载struts-2.1.6源码
wget https://archive.apache.org/dist/struts/binaries/struts-2.1.6-all.zip
2.2解压struts2-blank-2.1.6.war并参考其中配置
2.3拷贝struts.xml文件至项目src目录下
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>
<constant name="struts.enable.DynamicMethodInvocation" value="false" />
<constant name="struts.devMode" value="true" />
<!-- 将value值改为true,防止修改struts.xml文件,没有动态加载-->
<include file="example.xml"/>
<package name="default" namespace="/" extends="struts-default">
<default-action-ref name="index" />
<action name="index">
<result type="redirectAction">
<param name="actionName">HelloWorld</param>
<param name="namespace">/example</param>
</result>
</action>
</package>
<!-- Add packages here -->
</struts>
2.4拷贝依赖包至项目lib下
依赖包如:commons-fileupload-1.2.1.jar、commons-io-1.3.2.jar、commons-logging-1.1.jar、freemarker-2.3.13.jar、ognl-2.6.11.jar、struts2-core-2.1.6.jar、xwork-2.1.2.jar
3. 修改web.xml文件
<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>
将如下内容添加在项目web.xml文件中
4. 源码查看
struts2-core-2.1.6.jar—>Properties—>Java Source Attachment—>External File—>F:\develop\struts\struts-2.1.6\src\core\src\main\java(此处配置源码位置)
5. JavaDoc文档配置
struts2-core-2.1.6.jar—>Properties—>Javadoc Location—>Browse—>file:/F:/develop/struts/struts-2.1.6/docs/struts2-core/apidocs/(此处配置javadoc位置)
选中某类,F1,关联相应javadoc文档
6. 提示代码功能配置
window—>properties—>XML Catalog—>Add
Location:F:\develop\struts\struts-2.1.6\lib\struts2-core-2.1.6\struts-2.0.dtd(根据自己解压位置配置)
Key type:URI
Key:http://struts.apache.org/dtds/struts-2.0.dtd
###备注解压struts2-core-2.1.6.jar文件