struts多模塊

Struts多模塊:
struts是在第一次收到对action的请求(注意:不包括jsp的请求)时,提取这个请求的url的路径信息,把相应模块的mapping信息设置到请求中去。如果在进入一个模块时,第一次访问的是一个jsp页面,而在这个jsp页面中提交到该模块的一个action,就会出现找不到action mapping的情况。这就是因为,在进到这个模块时,访问的是jsp,这个模块的任何一个action都没有被访问到,所以struts的ActionServlet还没有来得及把这个模块的mapping设置到请求中,自然找不到该模块的action。 因此,这就引出一个约定,就是系统中尽量避免对Jsp的直接访问,如果要访问也要通过action来forward。虽然看起来麻烦一点,但是安全性、健壮性都会有所提高。
实现模块间跳转:
(1)用SwitchAction,主要用于实现页面的跳转
(2)全局转发和局部转发,用于实现模块间的跳转
(3)采用html:link标签
web.xml:
<init-param>
<param-name>config/store</param-name>
<param-value>/WEB-INF/struts-config-store.xml</param-value>
</init-param>
struts-confg.xml:
<form-bean name="clientForm" type="form.store.ClientForm" />
<action name="clientForm" path="/toStore" type="org.apache.struts.actions.SwitchAction" />
struts-confg-store.xml:
<form-bean name="clientForm" type="form.store.ClientForm" />
<action attribute="clientForm" name="clientForm" path="/clientInsert"/ >
<action forward="/clientinsert.jsp" path="/clientInit" />
clientinsert .jsp页面:
如果是第一次进入store模块就要用下面的:(toStore和clientInsert对应的form要是同一个Form)
<html:form method="post" action="/toStore?prefix=/store&page=/clientInsert.do" >
如果已经进入store模块则用:<html:form action="clientInsert " >
从另一模块到store
<html:link module="/store" action="/clientInit">或者
<html:link module="/store" page="/clientInit.do">
<html:link module="/store" href="/clientinsert.jsp ">
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值