LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 2601|回复: 3

【原创】Struts多模块应用的配置【原创】

[复制链接]
发表于 2005-5-12 23:13:14 | 显示全部楼层 |阅读模式
建立一个简单的多模块应用"Moduler"
[PHP]Moduler
        -index.jsp
        -module1
                -index.jsp
        -module2
                -index.jsp
        -WEB-INF
                -struts-*.tld
                -struts-config.xml
                -web.xml
                -lib
                        -*.jar
                -module1
                        -struts-config.xml
                -module2
                        -struts-config.xml
                -classes
                        -your_package[/PHP]
       
web-inf下面的struts-config.xml是struts应用默认配置
对子模块的配置文件可以放在任意的位置,为了让Tomcat能够找到它们的位置,你需要在web.xml中配置
<!-- module configurations -->
<init-param>
        <param-name>config/module1</param-name>
        <param-value>/WEB-INF/module1/struts-config.xml</param-value>
</init-param>

<init-param>
        <param-name>config/module2</param-name>
        <param-value>/WEB-INF/module2/struts-config.xml</param-value>
</init-param>

在应用的根目录下面分别建立子模块的目录:<WebRoot>/module1 <WebRoot>/module2。里面放置子模块自己的jsp,html和图片等资源。

这里需要注意,在配置web.xml时指定的"config/module1"就已经隐含的指定子模块的名字分别是module1,module2
所以,子模块的目录叫起名叫"module1"和"module2"

三个模块的struts配置:
默认模块(WEB-INF/struts-config.xml)
<action-mappings>
           <action path="/welcome" forward="/index.jsp"></action>
</action-mappings>

子模块1(WEB-INF/module1/struts-config.xml)
<action-mappings>
                <action path="/welcome" forward="/index.jsp"></action>
</action-mappings>

子模块2(WEB-INF/module2/struts-config.xml)
<action-mappings>
                <action path="/welcome" forward="/index.jsp"></action>
</action-mappings>

三个模块之间的跳转:
默认模块(index.jsp)
<html:link module="/module1" action="/welcome">转到子模块1的主页面</html:link>
<html:link module="/module2" action="/welcome">转到子模块2的主页面</html:link>

子模块1(module1/index.jsp)
<html:link action="../welcome">转到主页面</html:link>
<html:link module="/module2" action="/welcome">转到子模块2的主页面</html:link>

子模块2(module2/index.jsp)
<html:link action="../welcome">转到主页面</html:link>
<html:link module="/module1" action="/welcome">转到子模块1的主页面</html:link>

模块之间的跳转还可以通过配置struts-config.xml中的<forward>元素,具体方法可以参照struts-documentation的说明。

我是Struts新手,有什么错误请多指点!
共同进步!
发表于 2005-5-12 23:51:28 | 显示全部楼层
谢谢分享!
回复 支持 反对

使用道具 举报

发表于 2005-5-13 10:13:28 | 显示全部楼层
在<html:link/>的标记中好像没有module这个属性 :ask  :ask  :ask  :ask  :ask  :ask  :ask  :ask
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-5-13 10:26:26 | 显示全部楼层
这是Struts1.2的Documentation中的描述
<html:link>的module属性:
[PHP]Prefix name of a Module that contains the action mapping for the Action  that is specified by the action attribute. You must specify an action attribute for this to have an effect.

Note: Use "" to map to the default module.
[RT Expr][/PHP]
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表