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: config/store /WEB-INF/struts-config-store.xml struts-confg.xml: struts-confg-store.xml: <action attribute="clientForm" name="clientForm" path="/clientInsert"/ > 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 ">