struts中的多模块开发

struts多模块开发

  通常默认模块的配置文件名为:struts-config.xml,其它模块的命名方式一般为:struts-config-模块名.xml
对于多模块的情况,配置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"/> 

 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值