<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<!-- 添加struts2请求后缀常量 -->
<!-- <constant name="struts.action.extension" value="action,do"></constant> -->
<!-- 当struts的配置文件修改后,系统是否自动重新加载该文件,默认值为false -->
<constant name="struts.configuration.xml.reload" value="true"/>
<!-- 打开动态方法调用 -->
<constant name="struts.enable.DynamicMethodInvocation" value="true"/>
<package name="user" namespace="/" extends="struts-default">
<!-- 测试动态方法调用 -->
<action name="HelloAction" class="com.action.HelloAction">
<result name="success">/index.jsp</result>
<result name="success2">/index.jsp</result>
<result name="success3">/index.jsp</result>
</action>
<!-- 测试通配符配置-->
<action name="HelloAction_*" class="com.action.HelloAction" method="{1}">
<result name="success">/index.jsp</result>
<result name="success2">/index.jsp</result>
<result name="success3">/index.jsp</result>
</action>
</package>
</struts>
<?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.3.dtd">
<struts>
<!-- 添加struts2请求后缀常量 -->
<constant name="struts.action.extension" value="action,do"></constant>
<!-- 当struts的配置文件修改后,系统是否自动重新加载该文件,默认值为false -->
<constant name="struts.configuration.xml.reload" value="true"/>
<!-- localhost:8080/struts2_20170906/test/HelloAction.action -->
<!-- name:必填,保证唯一,名称任意(通常使用模块名称) namespace:可选,如果有值,就需要在请求地址中添加 extends:必填,只有继承了struts-default,才能使用struts2的功能 -->
<package name="user" namespace="/" extends="struts-default">
<!-- name:必填,保证唯一,名称通常使用控制器类的名称 class:控制器的路径 method:控制器的方法 -->
<action name="HelloAction" class="com.action.HelloAction"
method="execute">
<!-- name:控制器中方法的返回字符串 -->
<result name="success">/index.jsp</result>
</action>
<action name="HelloAction2">
<result>/index.jsp</result>
</action>
<!---------------------------------------- dispatcher(默认值):转发到jsp chain:转发到action redirect:重定向到jsp redirectAction:重定向到action -->
<action name="HelloAction3" class="com.action.HelloAction"
method="execute">
<result name="success" type="dispatcher">/index.jsp</result>
</action>
<action name="HelloAction4" class="com.action.HelloAction"
method="execute">
<result name="success" type="chain">HelloAction</result>
</action>
<action name="HelloAction5" class="com.action.HelloAction"
method="execute">
</action>
<action name="HelloAction6" class="com.action.HelloAction"
method="execute">
<result name="success" type="redirectAction">
<param name="actionName">HelloAction</param>
</result>
</action>
</package>
</struts>
本文介绍了Struts2框架的配置方法,包括常量配置、包配置、动作配置等。展示了如何通过XML文件设置动态方法调用、结果类型及通配符配置等内容。
449

被折叠的 条评论
为什么被折叠?



