所有操作类是否都应在 struts.xml 中列出

发布于 2024-10-14 06:34:49 字数 243 浏览 1 评论 0原文

所有操作类都应该在 struts.xml 中列出吗?如果操作类未在 struts.xml 中列出,struts2 框架能否识别它们?

背景:我对 struts 比较陌生,并且被要求清理一些 struts2 代码。有一些类在 struts2.xml、任何 jsp 或 javascript 中都没有引用(我做了字符串搜索)。我想知道我是否可以删除这些。

编辑:我很确定其他 Java 类/库没有使用这些类。这是我想知道的 struts 部分。

Should all action classes be listed in struts.xml? Can the struts2 framework be aware of action classes if they are not listed in struts.xml?

Background: I am relatively new to struts and have been asked to cleanup some struts2 code. There are some classes that are not referred in struts2.xml, any jsp or javascript (I did a string search). I was wondering if I could remove these.

EDIT: I am pretty sure these classes are not used by other Java classes/libraries. It is the struts part I was wondering about.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

单身狗的梦 2024-10-21 06:34:49

为了以其预期形式用作 Web 操作,必须满足以下四种可能性之一:

  1. 该类在 struts.xml 中列出
  2. 该类使用 struts 注释进行注释
  3. 该类由另一个操作类继承
  4. 您的项目正在使用约定插件,正如@Christina提到的

如果您正在查看的类不在struts.xml中,没有注释,没有在项目中的其他任何地方引用,并且该项目没有包含约定插件,那么您应该走吧。

唯一的其他问题是寻找其他 *.xml 文件。 struts.xml 能够将其他 xml 文件包含到其中,以便此类的实际操作配置可以驻留在不同的 xml 文件中。

In order to be used in their intended form as a web action, one of the following four possibilities must be true:

  1. The class is listed in the struts.xml
  2. The class is annotated with struts annotations
  3. The class is inherited by another action class
  4. Your project is using the convention plugin, as mentioned by @Christina

If the class you are looking at is not in struts.xml, is not annotated, is not referenced anywhere else in the project, and the project has not included the convention plugin, you should be good to go.

The only other gotcha would be to look for other *.xml files. struts.xml is capable of including other xml files into it, so that the actual action configuration for this class may reside in a different xml file.

我很坚强 2024-10-21 06:34:49

不,并非所有 Struts2 操作都需要在 xml 文件中声明。如果您使用约定插件,那么 Struts2 框架还会识别名为 struts、struts2、action 或实现 com.opensymphony.xwork2.Action 或名称以 Action 结尾的操作的包中包含的所有类。当然,约定插件也可以配置为识别其他类。有关约定插件如何工作的更多详细信息,请参见此处 (http://struts.apache.org/2.1.6/docs/convention-plugin.html)。

No, not all Struts2 actions need to be declared in an xml file. If you are using the convention plugin then the Struts2 framework is also aware of all classes included in packages named struts, struts2, action or actions which implement com.opensymphony.xwork2.Action or have a name ending with Action. Of course the convention plugin can also be configured to recognise other classes as well. See here (http://struts.apache.org/2.1.6/docs/convention-plugin.html) for more details on how the convention plugin works.

机场等船 2024-10-21 06:34:49

是的,他们必须如此。这是公认的、正确的做法。

Yes they have to be. That's the accepted and correct practice.

一抹微笑 2024-10-21 06:34:49

如果任何操作类未在 struts.xml 中列出,并不意味着应用程序不需要它。您不能仅仅因为某个类未在 struts.xml 中列出而将其删除。它可能已被其他一些类内部使用。

If any action class is not listed in the struts.xml it doesnt mean that it is not required by the application. You cannot remove a class just because it is not listed in struts.xml. It may have been used internally by some other class.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文