浏览 1947 次
锁定老帖子 主题:struts多模塊
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2008-07-29
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 "> 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |