准备材料
下载apache struts2压缩包 下载地址:[点击下载](https://struts.apache.org/)eclipse 准备
- 建立一个动态Web 工程
- 找到下载的struts-2.5.22-all
打开struts-2.5.22-all\struts-2.5.22\lib
找到如下jar 包,添加到 新建 web 工程的 web-inf/lib 文件夹下
- 复制 以上jar 包到 新建web 工程的 lib 目录下(多了也可能出错)
- 配置 web.xml 文件(参考 解压 web-inf / web.xml 文件)
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="starter" 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">
<!-- Filters -->
<!-- START SNIPPET: filter -->
<filter>
<filter-name>action2</filter-name>
<filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<!-- END SNIPPET: filter -->
<filter-mapping>
<filter-name>action2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
-
复制解压文件 中 WEB-INF/classes/struts.xml 到 新建web 工程的 src目录下
-
编辑 struts.xml(保留如下部分)
-
此时输入左尖括号若没有提示,则复制上图中框住的部分,打开 eclipst 工具栏中 window/preferences/XML/XML Catalog
1)添加RUL 复制的http://struts.apache.org/dtds/struts-2.5.dtd
2)ocaion 点 File System
解压路径下的\struts-2.5.22-all\struts-2.5.22\src\core\src\main\resources
添加对应的 struts.dtd 文件
3)OK 确定添加
8. 在 struts.xml 文件中 输入 < 有提示即可