您的位置:首页 > 编程语言 > Java开发

Struts模块化开发学习小结

2007-05-21 18:22 260 查看
Struts模块化开发学习小结:
1、 采用struts1.1及以上版本
2、 采用多配置文件,一个模块一个配置文件(一个核心struts-config.xml和多个struts-config-xxxx.xml),需要在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/View</param-name>
<param-value>/WEB-INF/struts-config-View.xml</param-value>
</init-param>
<init-param>
<param-name>config/Login</param-name>
<param-value>/WEB-INF/struts-config-Login.xml</param-value>
</init-param>
3、 多模块采用多文件夹目录(对应模块名)管理,比如以下(注意文件夹Login和View):

4、 其他注意事项:
1) 模块名与对应模块配置文件后缀一致
<init-param>
<param-name>config/View</param-name>
<param-value>/WEB-INF/struts-config-View.xml</param-value>
</init-param>
以上配置中,模块名为View,config/View前的config不可少。
模块名为View,则对应模块配置文件则为struts-config-View.xml
2) 应用于某模块的jsp文件统计一放置到以模块名命名的文件夹中,并且对应模块配置文件中不需要指定某jsp文件所在的模块名路径。 

struts-config-View.xml内容如下:
<struts-config>
<action-mappings>
<action path="/list" type="com.moduler.ViewAction">
<forward name="0" path="/list.jsp" />
<forward name="1" path="/add.jsp" />
</action>
</action-mappings>
</struts-config>
注意在以上配置文件中配置jsp的path路径时,并没有写明所在模块名称View,因为控制器自动将配置文件对应模块名作为首路径寻找对应jsp。
另一配置文件同理:
<struts-config>
<action-mappings>
<action path="/index" forward="/index.jsp"/>
<action path="/index2" forward="/Node/index2.jsp"/>
</action-mappings>
</struts-config>
3) 在某个jsp文件中要实现模块间的跳转,也即一个模块的Action跳转到另一个模块的Action,可以使用以下两种方式:
以从模块View下的add.jsp跳转到模块Login下的index.jsp为例,在add.jsp中加入以下即可:
A.<a href="/moduler/Login/index.do">转到login</a>
B.<a href="/moduler/ModuleSwitch.do?prefix=/Login&page=/index.do">转到login</a>
以上B方法采用了struts1.1中的SwitchAction类,并且需要在struts-config.xml中提前作如下配置:
<action-mappings>
<action path="/ModuleSwitch" type="org.apache.struts.actions.SwitchAction"/>
</action-mappings>
4)如要在模块外,或者全局跳转,仍需要在struts-config.xml中作相应配置。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: