5. 为应用指定多个struts配置文件
在大部分应用里,随着应用规模的增加,系统中Action的数量也会大量增加,导致struts.xml配置文件变得非常臃肿。为了避免struts.xml文件过于庞大、臃肿,提高struts.xml文件的可读性,我们可以将一个struts.xml配置文件分解成多个配置文件,然后在struts.xml文件中包含<include>
其他配置文件。下面的struts.xml通过<include>
元素指定多个配置文件:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<include file="struts-user.xml"/>
<include file="struts-order.xml"/>
</struts>
struts-user.xml文件配置如下:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<package name="day01" namespace="/day01" extends="struts-default">
<action name="helloworld" class="" method="execute">
<result name="success">...</result>
</action>
</package>
</struts>
注意struts-user.xml配置文件DOCTYPE
等不能少。通过这种方式,我们就可以将Struts 2的Action按模块添加在多个配置文件中。
转载请注明出处:http://blog.csdn.net/mark_lq/article/details/49813887