java Struts2 以单一形式处理多个动作
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14466733/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Struts2 handle multiple actions in single form
提问by gmeka
I have a form contains three buttons print
/export
/save
.
我有一个表单包含三个按钮print
/ export
/ save
。
<s:form action="/userAction">
<s:submit type="image" value="%{'print'}" src="/print.png" />
<s:submit type="image" value="%{'export'}" src="/export.png" />
<s:submit type="image" value="%{'save'}" src="/save.png" />
</s:form>
How can I map this in struts.xml
?
我怎样才能把它映射到struts.xml
?
采纳答案by Roman C
In the struts.xml
the action is mapped via the <action
tag
在struts.xml
动作是通过<action
标签映射的
<action name="userAction" class="...
the submit buttons should include method
attribute to call corresponding methods of the action
提交按钮应包含method
属性以调用相应的操作方法
<s:submit type="image" value="%{'print'}" src="/print.png" method="print" />
<s:submit type="image" value="%{'export'}" src="/export.png" method="export" />
<s:submit type="image" value="%{'save'}" src="/save.png" method="save" />
回答by Aleksandr M
In order to use method
attribute of the <s:submit>
tag DynamicMethodInvocation
must be enabled. Another solution is to use action
attribute.
为了使用标签的method
属性,必须启用。另一种解决方案是使用属性。<s:submit>
DynamicMethodInvocation
action
In JSP:
在 JSP 中:
<s:form action="save">
<s:submit type="image" value="%{'print'}" src="/print.png" action="print" />
<s:submit type="image" value="%{'export'}" src="/export.png" action="export" />
<s:submit type="image" value="%{'save'}" src="/save.png" />
</s:form>
In struts.xml:
在 struts.xml 中:
<action name="print" class="...">
<result>...</result>
</action>
<action name="export" class="...">
<result>...</result>
</action>
<action name="save" class="...">
<result>...</result>
</action>