Jakarta ee 如何仅使用一个action类而不使用dispatch操作或lookupdispatch操作在struts中插入、更新和删除?

Jakarta ee 如何仅使用一个action类而不使用dispatch操作或lookupdispatch操作在struts中插入、更新和删除?,jakarta-ee,struts2,Jakarta Ee,Struts2,如何编写一个只使用一个action类而不使用dispatch action或lookupdispatch action在struts中插入、更新和删除的程序?有可能吗 你写了一个动作: class ProductAction extends ActionSupport{ public String insert(){...} public String update(){...} public String delete(){...} public String

如何编写一个只使用一个action类而不使用dispatch action或lookupdispatch action在struts中插入、更新和删除的程序?有可能吗

你写了一个动作:

class ProductAction extends ActionSupport{
    public String insert(){...}
    public String update(){...}
    public String delete(){...}
    public String view(){...}
}
有两种方法可以实现你的目标

首先,动态方法调用继承自webwork。它是一个嵌入式功能,您不需要做任何事情。对“http://baseurl/product!insert.action“指向ProductAction并调用其insert方法而不是execute方法。它使用“!”来声明要调用的方法

第二种方法是使用通配符方法。 您将您的操作配置为以下内容:

<action name="product_*" class="actionpackage.ProductAction" method="{1}">


对“product\u insert.action”的引用将调用insert方法。

而不使用dispatch action或lookupdispatch action?你能澄清一下吗?你好像在用
struts1
。为什么不能切换到
struts2
?在
struts1
中,如果不使用
DispatchAction
,则无法执行此操作。为什么要执行此操作?这就是他们的目的。好吧。请告诉我更多关于ActionSupport类的信息,以及我需要在哪里编写execute或它不是必需的?这个答案是针对struts 2的,而不是struts 1。此外,您示例中的那些操作方法应该返回字符串,而不是void。是的,它是针对struts2的。我从未使用过struts1。致用户1578217:如果您使用struts1,我无法帮助您,对此表示抱歉。史蒂文·贝尼特斯:谢谢,我已经修改了。