3、配置文件笔记

<?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>

    <!-- 动态方法禁用常量,官方不推荐,意味着以后可能取消该功能 -->

    <constant name="struts.enable.DynamicMethodInvocation" value="false" /> 

    <constant name="struts.i18n.encoding" value="UTF-8" />

    <constant name="struts.action.extension" value="action,do"/>

    <constant name="struts.configuration.xml.reload" value="true" /> 

    <constant name="struts.devMode" value="true" />

    <constant name="struts.ui.theme" value="simple" /> 

    <!-- 限制上传文件大小,注上传大文件的话必须通过应用程序实现,如视频网站安装的浏览器插件即是通过socket编程的应用程序 -->

    <constant name="struts.multipart.maxSize" value="107015454096"/>

    <!-- 

                            struts2 配置文件讲解

    (1)包来管理action,和java中的类包非常相似,但是不跟javabean的类包一一对应,用于管理一组业务;

    (2)namespace命名空间,可以减少重复部分的代码,相对于struts1来说少写了很多代码,作为访问路径的一部分;

    (3)extends继承,以后大部分都继承自struts-default的包,因为其有很多拦截器,有核心功能;其在struts-core核心包中;

    (4)包可通过abstract="true"定义为抽象包,其中不可以有acion;

    (5)action:name可以作为访问路径名称;

    (6)将*.jsp文件放到WEB-INF路径下原因:a>不希望用户通过路径直接访问;b>直接访问*.jsp是没有意义的,要通过action访问才有意义;

    (7)jsp页面中通过${message}表达式获取message与字段msg成员变量名称无关,与其getMessage成员方法有关,一定要有其get方法;

    (8)execute方法一定要返回String类型;

    -->


   

    <!--

    namespace如果不配置,则为默认命名空间,则在action搜索路径的时候,在命名空间找不到的action,就会去默认命名空间下去寻找其action; 

     -->


   

    <!-- <package name="itcast" namespace="/control/employee" extends="struts-default">

       

       

        ***全视图,只能在本包内使用*********************

        如果要使所有的包都可以用,则可以采用继承的方式

        如:

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

            <global-results></global-results>

        </package>

        则其他的包继承base包即可:

        <package name"test" extends="base">

        </package>

        *******************************************

       

        <global-results>

            <result name="message">/WEB-INF/message.jsp</result>

        </global-results>

       

        <action name="message" class="cn.itcast.action.HelloWorldAction" method="add"/>

       

        <action name="list" class="cn.itcast.action.HelloWorldAction" method="execute">

            <result name="success" type="redirect">/employeeAdd.jsp?username=${username}</result>

        </action>

       

             a>如果没有为action指定class,默认是ActionSupport;

             b>如果没有为action知道method,默认是action中的execute方法;

             c>如果没有知道result的name属性,默认是success;

             ***注:如果只要转发功能的话,则就可以这么配置***

       

        <action name="addUI">

            <result>/WEB-INF/employeeAdd.jsp</result>

        </action>

       

        <action name="redirect">

            <result type="redirect">/redirect.jsp</result>           

        </action>

       

        重定向到别的命名空间的actionparam的配置

        <action name="redirectAction">

            <result type="redirectAction">list</result>

            <result type="redirectAction">

                <param name="actionName">xxx</param>

                <param name="namespace">/control/department</param>

            </result>

        </action>

       

        显示纯文本

        <action name="plainText">

            <result type="plainText">

                <param name="location">/index.jsp</param>

                <param name="charSet">UTF-8</param>

            </result>

        </action>

       

        为action属性注入值

        <action name="injectValue" class="cn.itcast.action.HelloWorldAction" method="inject">

            <param name="company">张敏鹏的公司</param>

            <result>/WEB-INF/inject.jsp</result>

        </action>

       

    </package>

   

    <package name="other" namespace="/control/department" extends="struts-default">

        <action name="xxx">

            <result>/WEB-INF/hello.jsp</result>

        </action>

    </package>

   

    改变处理请求的后缀部署,多种用逗号分开,默认处理action

    struts加载常量的配置文件的顺序:

    struts-default.xml,

    struts-plugin.xml,

    struts.xml,<推荐>

    struts.properties,

    web.xml

    <constant name="struts.action.extension" value="action,do"/>

    <constant name="struts.configuration.xml.reload" value="true" /> 

     -->


    <!-- 为应用指定多个struts配置文件,以功能模块为划分 -->

    <include file="department.xml"/>

    <include file="employee.xml"/>

</struts>





原文地址:https://www.cnblogs.com/zmpandzmp/p/3649035.html