简体   繁体   English

可以在Struts1的struts-config.xml文件中定义类方法名称吗?

[英]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? 是否有办法在Struts1的struts-config.xml配置文件中的Action类(Action,BaseAction,DispatchAction等)中定义执行哪个方法名称?

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. 我知道默认情况下, DispatchAction.execute()方法将解析“方法”参数的参数列表并执行该方法,但是我希望看看是否有一种方法可以像我一样在配置文件中定义该方法可以在Struts2中完成。

Is the Struts1 framework able to support this out of the box? Struts1框架能够立即支持吗?

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. 您可以在新控制器中扩展org.apache.struts.action.Action ,并从覆盖的execute()方法中调用所需的任何execute方法,然后添加的每个新操作都将扩展新控制器。

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: 我从未尝试过的另一种方法是在以下元素的项目配置的struts-tiles.tld中进行修改以指定您自己的控制器:

<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. 只需在struts配置中为DispatchActionMapping定义参数param。 Call it 'method' or 'action' or whatever. 称其为“方法”或“动作”或其他。 The assigned/passed value in URL must match the exact name of the method in your DispatchAction. URL中分配/传递的值必须与DispatchAction中方法的确切名称匹配。 Method signature with the four params. 具有四个参数的方法签名。 Return Type ActionForward. 返回类型ActionForward。 There is no other way. 没有别的办法了。 I believe you already know this approach. 我相信您已经知道这种方法。 That's the most 'out of the box' case. 这是最“开箱即用”的案例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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