struts2核心配置之struts.xml

本文深入解析Struts2框架的配置细节,包括常量配置、包配置和包含配置的使用方法。介绍了如何在struts.xml中配置常量,包配置中的关键属性及作用,以及如何通过<include>元素包含其他配置文件。

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配置文件

 

转载于:https://www.cnblogs.com/GG-Bond/p/10505407.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值