在我的Struts应用程序中,我有一个名为Foo的动作。
<action name="Foo" class="some.path.here.foo">
<result name="SUCCESS" type="tiles">/foo.tiles</result>
</action>
通常它调用execute(),但我想调用另一个名为change()的方法。我怎么能这样做?
我的想法是这样的:
<form name="Foo" action="Foo" >
<s:textfield name="Mail" placeholder="Mail" />
<select name="someselect">
<s:iterator value="someblabla">
<option value="<s:property value="somevalue"/>" label="<s:property value="Description"/>"><s:property value="Name"/></option>
</s:iterator>
</select>
<s:submit method="change" value="Go!"></s:submit>
</form>
但是当我想这样做时,我得到了
HTTP Status 404 - No result defined for action some.path.is.here.Foo and result input
你能帮助我吗?
答案 0 :(得分:2)
execute是操作中的默认方法。如果您想要更改它,我认为您可以通过添加“方法”属性来修改操作的描述。像那样:
<action name="Foo" class="some.path.here.foo" method="change">
<result name="SUCCESS" type="tiles">/foo.tiles</result>
</action>
希望这个帮助
答案 1 :(得分:0)
您收到错误,因为struts需要'execute'方法,除非您明确指定。如果您的操作方法名称不同,则必须使用参数'method'指定它的明确性。
所以你的代码应该是
<action name="Foo" class="some.path.here.foo" method="change">
<result name="SUCCESS" type="tiles">/foo.tiles</result>
</action>
答案 2 :(得分:0)
Struts 2还支持通配符方法和动态方法调用。 DMI不太安全,不是首选。请参阅文档here