三大框架(ssh)学习——配置文件详解(二)

多配置文件实现

项目经常需要多人协作开发,但是如果大家都是用同一个struts.xml文件,会互相影响不利于开发的正常开展。这样,我们可以通过<include>元素指定多个配置文件。

可以在src下面建立多个struts配置文件。然后再struts.xml中分别引入:

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>

<constant name="struts.i18n.encoding" value="gbk" />

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

 

    <include file="struts_1.xml"></include>

    <include file="struts_2.xml"></include>

</struts>

struts_1.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>

    <package name="test" namespace="/ceshi" extends="struts-default">

        <action name="*_*" class="com.bjsxt.struts.test.{1}Action" method="{2}" >

          <result name="success">/{1}_{2}_ok.jsp</result>

        </action>

    </package>

</struts>

 

执行:http://localhost/teststruts/ceshi/First_test2   发现结果一切正常!

 

通过注解实现action的零配置

我们可以通过Annotation注解替代了传统xml文件配置的限制。我们可以通过struts2提供的注解:@Namespace,@Result,@Results等完全代替xml文件的配置。

 

本节内容,目前工作中用的并不多,一般写在配置文件中。

本节内容,作为自学内容!大家网上查资料,写出文档,写出测试类.大家来讲这个内容!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值