在 Struts 2 中配置动作有不同的方法吗? [英] Is there a different way to configuring actions in Struts 2?

查看:14
本文介绍了在 Struts 2 中配置动作有不同的方法吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将遗留(Struts 1)代码迁移到 Struts2.

I have requirement to migrate legacy (Struts 1) code to Struts2.

如果同一个action类中有多个方法,我们可以在一个<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.那么,我可以在单个 <action> 标签中配置这两种方法(showshowErr)吗?

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆