在 Struts 2 中是否有不同的方式来配置动作? [英] Is there a different way to configuring actions in Struts 2?
问题描述
我需要将遗留 (Struts 1) 代码迁移到 Struts2.
I have requirement to migrate legacy (Struts 1) code to Struts2.
如果在同一个action类中有多个方法,我们可以在单个
标签中配置它们吗?
If there are multiple methods in same action class, can we configure them in single <action>
tag?
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>
这里,我有单个操作,即 product
和单个操作类,即 ProductAction
.那么,我可以在单个
标签中配置这两种方法(show
、showErr
)吗?
Here, I have single action i.e. product
and single action class i.e. ProductAction
. So, can I configure both the methods (show
, showErr
) in single <action>
tag?
推荐答案
如果在同一个包中使用,操作名称将被覆盖.操作名称映射到特定方法或 execute
.
The action name is overridden if used in the same package. The action name maps to a specific method or execute
.
您可以使用通配符映射在操作中放置方法名称.
You can use wildcard mapping to put a method name in the action.
<action name="*product" class="com.ProductAction" method="{1}">
这篇关于在 Struts 2 中是否有不同的方式来配置动作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!