zoukankan      html  css  js  c++  java
  • struts2核心配置之struts.xml

    struts.xml

      -常量配置

      -包配置

      -包含配置

    一、常量配置

    struts2常量的配置通常采用三种方式:

    1、在struts.xml中使用<constant>元素配置常量

    <struts>
        <constant name="struts.i18n.encoding" value="UTF-8"></constant> <!-- 设置默认编码为utf-8 -->
        <constant name="struts.devMode" value="true"></constant> <!-- 设置使用开发模式 -->
    </struts>

    2、在struts.properties文件中配置常量

    3、在web.xml中通过<init-param>配置常量

    二、包配置

    Struts2框架的核心组件是Action和拦截器,它使用包来管理Action和拦截器,每个包就是多个Action,多个拦截器和引用的集合。

    明白了package的地位,就跟我一起来学习学习,come

    package常用属性

    属性 说明 是否必须
    name 指定该包的名字,唯一标识符,此名字是被其他包引用的key
    namespace 该包的命名空间
    extends 继承其他包,可以继承其他包中的Action定义,拦截器定义
    abstract 指定该包是否是一个抽象包

    extends通常设置为struts-default,使该包中的Action具有Struts2框架中的默认拦截器等功能。 

    <package name="TestFirst" namespace="/" extends="struts-default"> 
            <action name="FirstT" class="com.test.pojo.TestAction">
                <result name="success">/success.jsp</result>
            </action>
            <action name="hello" class="com.test.pojo.TestAction" method="hello">
                <result name="hello">/hello.jsp</result>
            </action>
     </package>

    namespace设置为" / "或不写,访问Action路径为项目路径+actionName

    namespace设置为” /* “,访问Action路径为i项目路径+” /* “+actionName

    三、包含配置

    <include>用来在struts.xml中包含其他配置文件

    <include file="struts-HHH.xml"></include>
    <include file="struts-KKK.xml"></include>

    没一个被包含的配置文件都必须是标准的struts配置文件

  • 相关阅读:
    bzoj2669 [cqoi2012]局部极小值 状压DP+容斥
    bzoj2560 串珠子 状压DP
    bzoj2004 [Hnoi2010]Bus 公交线路 矩阵快速幂+状压DP
    「校内训练 2019-04-23」越野赛车问题 动态dp+树的直径
    bzoj5210 最大连通子块和 动态 DP + 堆
    动态 DP 学习笔记
    bzoj4987 Tree 树上背包
    bzoj1190 [HNOI2007]梦幻岛宝珠 背包
    bzoj1004 [HNOI2008]Cards Burnside 引理+背包
    bzoj4922 [Lydsy1706月赛]Karp-de-Chant Number 贪心+背包
  • 原文地址:https://www.cnblogs.com/GG-Bond/p/10505407.html
Copyright © 2011-2022 走看看