代码改变世界

2、Struts2引入多个配置文件

2015-10-15 17:51  怡红院丿无痕  阅读(210)  评论(0编辑  收藏  举报

1、关于核心配置文件 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>

    <include file="com/baowei/action/userAction.xml" />
    <include file="constant.xml" />


</struts>

2、关于Action的配置文件Action.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>

    <package name="mypackage" extends="struts-default">


        <!-- <action name="User_add" class="com.baowei.action.UserAction" method="add"> 
            <result name="add">/User/add.jsp</result> </action> <action name="User_delete" 
            class="com.baowei.action.UserAction" method="delete"> <result name="delete">/User/delete.jsp</result> 
            </action> -->

        <!-- <action name="User" class="com.baowei.action.UserAction"> <result 
            name="add">/User/add.jsp</result> </action> -->


        <action name="*_*" class="com.baowei.action.{1}Action" method="{2}">
            <result name="{2}">/{1}/{2}.jsp</result>
        </action>


    </package>


</struts>

3、关于struts2一些常量的配置文件constant.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>

    <!-- 一、全局配置 -->
    <!-- 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>