struts中的一些常用配置

本文介绍了Struts2框架的配置方法,包括常量配置、包配置、动作配置等。展示了如何通过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.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>



评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值