更新时间:2022-12-23 18:37:20
您可以在 struts.xml
文件中定义两个动作,并使用
标签的 action
属性来提交不同的动作 http://struts.apache.org/docs/submit.html.
You can define two actions in struts.xml
file and use action
attribute of <s:submit>
tag in order to submit to different actions http://struts.apache.org/docs/submit.html.
在 JSP 中:
<s:submit value="Search" action="searchEmployeeAction"/>
<s:submit value="Add New" action="addEmployeeAction"/>
在 struts.xml 中:
In struts.xml:
<action name="addEmployeeAction" method="add" class="example.EmployeeAction">
<result>/example/add.jsp</result>
</action>
<action name="searchEmployeeAction" method="search" class="example.EmployeeAction">
<result>/example/search.jsp</result>
</action>
并在您的操作中创建两个 public String
方法 add
和 search
.
And in your action create two public String
methods add
and search
.
阅读多个提交按钮http://struts.apache.org/docs/multiple-submit-buttons.html.
更新
从 Struts2 版本 2.3.15.3 开始,您需要将 struts.mapper.action.prefix.enabled
常量设置为 true 以启用对 action:
前缀的支持.
Starting from Struts2 version 2.3.15.3 you need to set struts.mapper.action.prefix.enabled
constant to true in order to enable support for action:
prefix.
把它放在你的 struts.xml
文件中:
Put that in your struts.xml
file:
<constant name="struts.mapper.action.prefix.enabled" value="true" />