为便于开发,配置,管理,松耦的优点。
配置Struts应用的多模块!
0.web.xml
如
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<init-param>
<param-name>config/moduleA</param-name>
<param-value>/WEB-INF/struts-moduleA.xml</param-value>
</init-param>
<init-param>
<param-name>config/moduleB</param-name>
<param-value>/WEB-INF/struts-moduleB.xml</param-value>
</init-param>
1.其中struts-config.xml
<action path="/toModule"
type="org.apache.struts.actions.SwitchAction" />
<action path="/default"
type="com.zh.love.struts.action.DefaultAction">
<forward name="success"
path="/toModule.do?prefix=/moduleA&page=/loginA.do?method=one">
</forward>
</action>
其中,/toModule这一块是必写的,用于不同模块之间的转向等处理工作
下面的/default,如现在调用/default.do,如果success则现在转向执行moduleA模块的LoginAAction的one方法,这里的Action是继承DispatchAction,在模块的xml配置文件中增加了parameter="method",因此在调用时为/loginA.do?method=one
2.另外struts-moduleA.xml
<action path="/toModule" type="org.apache.struts.actions.SwitchAction" />
<action path="/loginA"
parameter="method"
type="com.zh.love.struts.action.modulea.LoginAAction" >
<forward name="success" path="/toModule.do?prefix=/moduleB&page=/loginB.do"></forward>
</action>
注:成功再转向模块B,(是不是感觉这例子写的有点无聊?唏唏)
3.struts-moduleB.xml
<action path="/loginB" type="com.zh.love.struts.action.moduleb.LoginBAction" />