[英]Is there a different way to configuring actions in Struts 2?
I have requirement to migrate legacy (Struts 1) code to Struts2.我需要将遗留(Struts 1)代码迁移到 Struts2。
If there are multiple methods in same action class, can we configure them in single <action>
tag?如果在同一个 action 类中有多个方法,我们可以在单个<action>
标签中配置它们吗?
struts.xml struts.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<package name="default" extends="struts-default">
<action name="product"
class="com.ProductAction"
method="show">
<result name="success">welcome.jsp</result>
</action>
<action name="product"
class="com.ProductAction"
method="showErr">
<result name="error">error.jsp</result>
</action>
</package>
</struts>
Here, I have single action ie product
and single action class ie ProductAction
.在这里,我有单一动作,即product
和单一动作类,即ProductAction
。 So, can I configure both the methods ( show
, showErr
) in single <action>
tag?那么,我可以在单个<action>
标签中配置这两种方法( show
、 showErr
)吗?
The action name is overridden if used in the same package.如果在同一个包中使用,操作名称将被覆盖。 The action name maps to a specific method or execute
.操作名称映射到特定方法或execute
。
You can use wildcard mapping to put a method name in the action.您可以使用通配符映射将方法名称放入操作中。
<action name="*product" class="com.ProductAction" method="{1}">
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.