web.xml的分发器代码:
<!-- 引入struts核心过滤器 -->
<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>
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="hello" extends="struts-default">
<action name="hello" class="action.HelloAction" method="execute">
<result name="success">/index.jsp</result>
</action>
</package>
</struts>
常用的常量配置
<struts>
<!-- 0. 请求数据编码 -->
<constant name="struts.i18n.encoding" value="UTF-8"/>
<!-- 1. 修改Struts默认的访问后缀 -->
<constant name="struts.action.extension" value="action,do,"></constant>
<!-- 2. 修改xml自动重新加载 -->
<constant name="struts.configuration.xml.reload" value="true"/>
<!-- 3. 开启动态方法调用 (默认不开启)-->
<constant name="struts.enable.DynamicMethodInvocation" value="true"/>
<!-- 4. 修改上传文件的最大大小为30M -->
<constant name="struts.multipart.maxSize" value="31457280"/>
</struts>