struts中的多模块开发方法

2014-11-18 14:38:46 · 作者: · 浏览: 22

  通常默认模块的配置文件名为:struts-config.xml,其它模块的命名方式一般为:struts-config-模块名.xml,对于多模块的情况,配置web.xml文件的ActionServlet类的一个初始化参数。


config
/WEB-INF/struts-config.xml

config/module1
/WEB-INF/struts-config-module1.xml

以“/module1”开头的路径访问的
module1模块的资源


  在模块间转换
  如果需要跳转到其他模块,进行模块跳转的URL必须给定两个参数:prefix和page
  其中prefix指明要 转到的模块前缀,如前其前缀值为’/module1’,page为要跳转的页面或其他资源.


  1.使用Struts内建的SwitchAction类
...
...


其中 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. 使用转发
...


其中 contextRelative="true" 表示当前path属性以“/”开头时,给出的是相对于当前上下文的URL


  3.使用 标记