struts多模块开发
对于多模块的情况,配置web.xml文件的ActionServlet类的一个初始化参数。
<init-param> <param-name>config</param-name> <param-value>/WEB-INF/struts-config.xml</param-value> </init-param> <init-param> <param-name>config/module1</param-name> <param-value>/WEB-INF/struts-config-module1.xml</param-value> </init-param> |
以“/module1”开头的路径访问的
module1模块的资源
在模块间转换
如果需要跳转到其他模块,进行模块跳转的URL必须给定两个参数:prefix和page其中prefix指明要 转到的模块前缀,如前其前缀值为'/module1',page为要跳转的页面或其他资源.
1.使用Struts内建的SwitchAction类
...
<action-mappings>
<action path="/toModule" type="org.apache.struts.actions.SwitchAction"/>
...
</action-mappings>
其中 path="/toModule" 指定了Action类的访问路径,如果要从当前模块跳转到另一模块:module1,链接为:
http://localhost:8080/xxx/toModule.do?prefix=/module1&page=/index.do
如果要从当前模块跳转到默认模块
http://localhost:8080/xxx/toModule.do?prefix=&page=/index.do
2. 使用转发
<global-forwards>
<forward name="toModule1" contextRelative="true" path="/module1/index.do" redirect="true"/>
...
</global-forwards>
其中 contextRelative="true" 表示当前path属性以“/”开头时,给出的是相对于当前上下文的URL
3.使用<html:link>标记
<html:link module="/module1" path="/index.do"/>