7.5. Forwarding Users to a Module
Problem
You want to forward control from one module to a page in another module.
Solution
If the link is for a JSP page and not an action, create an action of
type ForwardAction for that page in the target
module's struts-config.xml
file. Specify the path to the JSP page as the value of the
parameter attribute:
<action path="/module1Menu"
type="org.apache.struts.actions.ForwardAction"
parameter="/mod1/module1Menu.jsp"/>Then define a
global
forward, in the struts-config.xml file of the
source module, with the module attribute set to
the target module prefix and the path attribute
set to the name of the action you just created:
<forward name="goToModule1" module="/mod1" path="/module1.do"/>
If the link is for an action in the other module, then specify the
path to the action, making sure to include the Struts
ActionServlet prefix or suffix (for example,
.do):
<html:link forward="goToModule1">Go To Module 1</html:link>
Discussion
You would think that you could create a link to a page in another
module by specifying the module attribute on the
global forward:
<forward name="goToModule1" module="/mod1" path="/module1.jsp"/>
Unfortunately, this will not work. The URL to the page is correctly generated as http://localhost/jsc-ch07/mod1/module1.jsp; however, internally Struts still thinks that you are in the source module. Module-specific Struts entities such as global forwards and message resources will not be available on the target page because Struts has not switched ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access