Académique Documents
Professionnel Documents
Culture Documents
1Preface
1.1Objective
1.2Scope
Any struts application can use the solution discussed to control the flow.
There are two ways to specify the next resource in the flow.
<action path="/testaction"
type="com.mycom.test.TestAction"
parameter="method" >
<forward name="success" path="welcome.jsp" />
</action>
In most of the applications the first way is used to control the flow. Even when
the second method is used the destination resource is hardcoded or read from
a constants/properties file, but most of the times it is specific to an action.
The solution discussed here makes use of an XML to maintain the mapping
information, similar to the one shown below.
<config>
<action>
<name>/loginl</name>
<success>loginsuccess.jsp</ success>
<failure>loginfailure.jsp</ failure>
</action>
<action>
<name>/welcome</name>
<welcome>/general/welcome.jsp</welcome>
<b2bwelcome>/b2b//b2bwelcome.jsp</b2bwelcome>
</action>
</config>
4Custom ActionMapping
A Custom ActionMapping class is created which extends the Struts provided
ActionMapping. The forward method is overridden to pass the control to next
resource location, this method looks for the presence of the resource in the
Map object which gets updated at regular intervals,
map = DynamicMappingUtilPlugIn.getInstance().forwardMap;
if(map != null){
forwardPath = (String)map.get(getPath()+":"+forwardName);
if(forwardPath != null){
return super.findForward(forwardName);
}else{
return null;
The custom ActionMapping class can be associated with the <action> tag
using the attribute classname.
<action path="/welcome"
type="com.mycom.test.TestAction"
parameter="method"
className="com.mycom.struts.mapping.CustomActionMapping">
</action>
DynamicMappingUtilPlugIn.getInstance(servlet.getServletConfig());
/**
* @return
*/
if(dynamicMappingPlugIn == null) {
return dynamicMappingPlugIn;
/**
* @return
*/
if(dynamicMappingPlugIn == null) {
dynamicMappingPlugIn.init(servletconfig);
return dynamicMappingPlugIn;
log.debug("Initializing DynamicMappingCache...");
configPath = servletconfig.getServletContext().
starter.start();
log.debug("DynamicMappingCache initialized...");
try
Thread.sleep(10000);
while(true)
populateForwardMap();
Thread.sleep(cacheInterval);
catch(InterruptedException ex)
log.error(ex);
try {
DocumentBuilderFactory docBuilderFactory =
DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder =
docBuilderFactory.newDocumentBuilder();
doc.getDocumentElement().normalize();
listOfMappings = doc.getElementsByTagName("action");
NodeList childNodeList =
firstDataSetNode.getChildNodes();
if(childNodeList != null){
if(childNodeList.item(i).getNodeName().equals("name"))
nodeName = childNodeList.item(i).getChildNodes().
item(0).getNodeValue();
if(!childNodeList.item(i).getNodeName().equals("name") &&
childNodeList.item(i).hasChildNodes()){
forwardMap.put(nodeName + ":" +
childNodeList.item(i). getNodeName(),
childNodeList.item(i).getChildNodes().
item(0).getNodeValue());
}
}
err.printStackTrace();
} catch (SAXException e) {
e.printStackTrace();
Exception x = e.getException();
} catch (Exception t) {
t.printStackTrace();
return configFile;
return configRel;
configFile = string;
configRel = string;