新建一个动态web项目
在WebContent/WEB-INF/lib 目录导入 Struts2 相关包
structs.xml 配置文件
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.5.dtd">
<struts>
<!-- 配置一个包:package -->
<package name="demo1" extends="struts-default" namespace="/">
<!-- 配置Action -->
<action name="strutsDemo1" class="com.zju.action.StrutsDemo1">
<!-- 配置result结果页面跳转 -->
<result name="success">/demo2.jsp</result>
</action>
</package>
</struts>
web.xml 配置文件
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>WebProject</display-name>
<!-- 配置Struts2核心过滤器:前端控制器 -->
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
我遇到的问题是:
在web配置文件中核心滤波器的选择上出了问题:
structs2 的版本不同,选择的滤波器不同
2.5之前的用org.apache.struts2.dispatcher.filter.ng.StrutsPrepareAndExecuteFilter
2.5 版本的用
org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter