为什么struts2的action类中不需要main()?

发布于 2025-01-07 21:08:31 字数 218 浏览 6 评论 0原文

*大家好..! *

通常java程序需要main()函数来执行代码,否则会返回错误[java.lang.NoSuchMethodError: main Exception in thread "main"]..!在struts2中,我们使用动作类和动作类。 bean 类(java 代码),但它们不需要 main() 函数。这背后的概念是什么?顺便说一句,我是 Struts 框架的新手。

*Hello Guys..! *

Normally a java program needs main() function to execute the code otherwise it'll returns an error[java.lang.NoSuchMethodError: main Exception in thread "main"]..! In struts2 we are using action classes & bean classes(java codes) but they don't needs main() function in it. What is the concept behind this..? By the way I'm a newbie to the Struts framework.

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

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

发布评论

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

评论(2

预谋 2025-01-14 21:08:31

这是因为 Struts 框架提供了启动和运行应用程序的基础设施。作为框架的用户,您可以实现由框架代码调用的特定类。

Struts 本身运行在应用程序服务器(例如 Tomcat)内,通常该服务器包含最终负责启动应用程序的 main() 方法。

这是控制反转的示例——许多应用程序框架都是这样工作的。

This is because the Struts framework provides the infrastructure to get the application up and running. As a user of the framework, you implement specific classes that are called by the framework code.

Struts itself runs inside an application server such as Tomcat, and usually it is the server that contains the main() method which is ultimately responsible for starting up your application.

This is an example of inversion of control -- many application frameworks work this way.

初心 2025-01-14 21:08:31

在从命令行启动的应用程序中,您需要一个 main() 方法,因为这是 JVM 期望在这种情况下执行的 API。从其他框架内调用的代码必须实现该框架所需的任何 API。在许多情况下,框架实现 main() 并通过其他一些 API 调用您的代码。这通常比 public void main(String[] args) 更强大。在其他情况下,框架本身是从另一个抽象调用的(例如,应用程序容器内的Web框架内的Web应用程序)。

You need a main() method in applications started from the command line as that's the API that the JVM expects to execute in that case. Code called from within other frameworks must implement whatever API that framework expects. In many cases that framework implements main() and calls your code via some other API. This is usually more robust than public void main(String[] args) allows. In other instances the framework is itself called from another abstraction (e.g. a Web Application within a Web Framework within a App Container).

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