开发工具:
eclipse Neon (4.6.0)
struts2.5.2
struts2.5.2是struts当前最新版本,该版本与此前2.3版本的不同之处(包含但不仅限于):
1.struts2.5核心包已经将xwork的核心包含其中,因此在struts2版本包中的lib目录下已找不到xwork-core-xx.xx.xx.jar文件。
struts2.5.2版本下载地址 http://mirrors.tuna.tsinghua.edu.cn/apache/struts/2.5.2/struts-2.5.2-all.zip
实例目录结构:
实例下载地址:http://pan.baidu.com/s/1slOqKNF
1.使用eclipse创建动态Web项目。
将struts2.5版本包中\apps\struts2-showcase.war包解压,将lib目录下的以下jar包复制到eclipse项目中的WebContent/WEB-INF/lib目录下:
asm-3.3.jar
asm-commons-3.3.jar
asm-tree-3.3.jar
commons-fileupload-1.3.2.jar
commons-io-2.4.jar
commons-lang3-3.4.jar
commons-logging-1.1.3.jar
freemarker-2.3.23.jar
javassist-3.20.0-GA.jar
log4j-api-2.5.jar
ognl-3.1.10.jar
struts2-core-2.5.2.jar
2.在WEB-INF目录下创建web.xml文件(若创建项目时自动创建则不再需要重新创建),修改web.xml配置内容如下(参照struts2-showcase.war)的配置:
1 <?xml version="1.0" encoding="UTF-8"?> 2 <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1"> 3 <display-name>mystruts2</display-name> 4 <welcome-file-list> 5 <welcome-file>index.html</welcome-file> 6 <welcome-file>index.htm</welcome-file> 7 <welcome-file>index.jsp</welcome-file> 8 <welcome-file>default.html</welcome-file> 9 <welcome-file>default.htm</welcome-file> 10 <welcome-file>default.jsp</welcome-file> 11 </welcome-file-list> 12 <filter> 13 <filter-name>struts-prepare</filter-name> 14 <filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareFilter</filter-class> 15 </filter> 16 17 <filter> 18 <filter-name>struts-execute</filter-name> 19 <filter-class>org.apache.struts2.dispatcher.filter.StrutsExecuteFilter</filter-class> 20 </filter> 21 <filter-mapping> 22 <filter-name>struts-prepare</filter-name> 23 <url-pattern>/*</url-pattern> 24 </filter-mapping> 25 26 <filter-mapping> 27 <filter-name>struts-execute</filter-name> 28 <url-pattern>/*</url-pattern> 29 </filter-mapping> 30 </web-app>