Search code examples
javastrutsstruts-1url-mappingstruts-config

How to access path attribute of action tag (struts-config.xml) in Action or dispatch action class?


I am using unspecified method of DispatchAction and there is a situation where I need to know the contents of the path attribute of action tag in struts-config.xml, because this Action class is being used for two action paths.

eg:

<action **path="/auditor/adminOtherInfo"** **type="org.sae.aab.struts.action.OtherInfoAction"**
            scope="request" name="AdminOtherInfoForm" parameter="method" validate="false">
...
</action>

<action **path="/auditor/otherInfo"** **type="org.sae.aab.struts.action.OtherInfoAction"**
            scope="request" name="OtherInfoForm" parameter="method" validate="false">
...
</action>

I have highlighted path and type for more focussing.

I wanted to know the path because I wanted to set different parameters and redirect the flow accordingly.

help me please..


Solution

  • You can get it from ActionMapping. The action mapping is passed to the action as parameter when it executes.

    String path = mapping.getPath();