将应用划分为多个模块进行开发,可简化应用的并行开发过程,缩短应用的开发时间.struts的多模块开发大致包括以下几个部分:
一.配置文件
1.模块文件名称:struts-config-模块名称.xml
2.在web.xml中部署
a.<param-name>config/模块名称</param-name>
b.<param-value>模块配置文件路径</param-value>
二.设置模块文件内部属性
1.设置默认转发路径
a.在forward中设置contextRelative="true",跳转到path指定的路径
b.配置<controller>属性,设置forwardPattern="$M$p".$M指定目录,$P指定文件名.一般直接使用$P,而需要写出$M的值
注:一但使用了contextRelative="true"设置,就不能使用<controller>设置,否则<controller>元素的配置无效
三.模块切换使用
1.使用<forward>元素进行切换
例:<html:link forward="goMB">moduleB模块</html>
此时需在<global-forwards>中配置
a.<forward name="goMB" path="/模块名称/文件名.jsp" contextRelative="true">
b.<forward name="goMB" path="文件名.jsp" module="/模块名称">
注:此时module属性值必须以/开头,此时contextRelative不能为true
补充:上面的"文件名.jsp"也可换成其他可访问的名称.例:名称.do
2.使用<html:link>切换
a.<html:link page="/路径名" module="/模块名称">
b.若是切换到默认模块,使用<html:link page="/路径名" module="">
3.使用SwithcAction切换
a.在模块文件中配置
<action path="请求的uri"
type="org.apache.struts.action.SwitchAction"
........
>
b.使用
<html:link page="/请求的uri?prefix=/模块名称&page=/请求的uri"></html:link>
prefix指定的模块必须以/开头,并后面的page指定的uri必须是被指定模块下的相对路径