简体   繁体   中英

Can the class method name be defined in the struts-config.xml file in Struts1?

Is there a way to define which method name is executed in an Action class (Action, BaseAction, DispatchAction, etc) in the struts-config.xml configuration file in Struts1?

I know that by default, the DispatchAction.execute() method will parse the parameter list for a "method" parameter and execute that method, however I was hoping to see if there was a way to define the method in the configuration file as I can do in Struts2.

Is the Struts1 framework able to support this out of the box?

You can extend org.apache.struts.action.Action in your new controller and call any execute method you want from the overridden execute() method and then each new action you add will extends your new controller.

Another way that I never tried is to modify in struts-tiles.tld of your project configuration in the following element to specify your own controller:

<attribute>
     <name>controllerClass</name>
     <required>false</required>
     <rtexprvalue>true</rtexprvalue>
     <description>
     <![CDATA[
     <p>Class type of a controller called immediately before page is inserted.</p>
     <p>Controller is used to prepare data to be render by inserted Tile.</p>
     <p>See also controlerUrl</p>
     <p>Class must implements or extends one of the following :</p>
     <ul>
       <li>org.apache.struts.tiles.Controller</li>
       <li>org.apache.struts.tiles.ControllerSupport</li>
       <li>org.apache.struts.action.Action (wrapper org.apache.struts.action.ActionController is used)</li>
     </ul>
     <p>See also controllerUrl. Only one of controllerUrl or controllerClass should be used.</p>
     ]]>
     </description>
  </attribute>

Sorry it is too late in the evening. The following is exactly what you described above. Just define the parameter param for a DispatchActionMapping in struts config. Call it 'method' or 'action' or whatever. The assigned/passed value in URL must match the exact name of the method in your DispatchAction. Method signature with the four params. Return Type ActionForward. There is no other way. I believe you already know this approach. That's the most 'out of the box' case.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM