三大框架(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文件的配置。

 

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

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

猜你喜欢

转载自blog.csdn.net/weixin_38003467/article/details/83545790
今日推荐