Struts中的动作类执行流程 [英] Action class execution flow in Struts

查看:68
本文介绍了Struts中的动作类执行流程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给我的印象是Struts中的 execute()方法是从 struts.xml调用动作类时调用的第一个方法。但是,当我调试在动作类中具有构造函数的代码时,我看到该构造函数首先被执行(我在这里没有创建任何实例)。

I was in an impression thatexecute() method in Struts is the first method called when action class is invoked from struts.xml. But when I debug my code which has a constructor in action class, I see that constructor gets executed first(I am not creating any instance here).

1)能否请您解释一下动作类中的执行流程,即在实际执行之前调用了哪些方法。

1) Can some please explain the flow of execution in action class, i.e. what methods are called before actually getting to execute.

2)我不确定为什么构造函数被调用

2) I am not sure why constructor is getting called

推荐答案

Struts在执行动作之前会调用很多东西。但可以在 struts.xml 中进行配置。您可以从答案中查看操作执行的请求流。

Struts calls a lot of stuff before the action is executed. But it's configurable in struts.xml. You can see the request flow of the action execution from this answer.


内部Struts使用 ObjectFactory 来构建由以下对象定义的所有对象
配置。进一步了解 ObjectFactory docs
Struts 2请求流程

Internally Struts uses the ObjectFactory to build all objects defined by the configuration. See more about ObjectFactory docs or The Struts 2 Request Flow.






构造函数应具有默认构造函数无参数构造函数,否则将无法构建。有关差异的详细说明,请参见 Java默认构造函数


Constructors should have the default constructor or no-argument constructor, otherwise it won't be constructed. For detailed explanation about differences you can see Java default constructor.


您不必为类提供任何构造函数,但是
在执行此操作时必须小心。编译器会自动为任何没有构造函数的类提供
无参数的默认构造函数。
此默认构造函数将调用
超类的无参数构造函数。在这种情况下,如果
超类没有无参数构造函数,则编译器会抱怨,因此您必须验证
确实具有该参数。如果您的类没有显式超类,则它具有Object的
隐式超类,该类确实具有无参数的
构造函数。

You don't have to provide any constructors for your class, but you must be careful when doing this. The compiler automatically provides a no-argument, default constructor for any class without constructors. This default constructor will call the no-argument constructor of the superclass. In this situation, the compiler will complain if the superclass doesn't have a no-argument constructor so you must verify that it does. If your class has no explicit superclass, then it has an implicit superclass of Object, which does have a no-argument constructor.






在执行操作之前,方法主要由拦截器调用。默认的拦截器堆栈为 defaultStack 。它包含许多在操作之前执行的功能。请参阅答案以获得对默认配置的印象。


The methods are called mostly by interceptors before the action is executed. The default interceptor stack is defaultStack. It has a lot of functionality involved that is executed before the action. See this answer to get impression about default configuration.


拦截器在执行动作之前被调用。就像处理请求的
管道一样。他们每个人都接连调用
。最后一个拦截器处理完毕后,将执行该操作。
在动作配置中配置了要调用的拦截器,或者通过注释配置了
。有关拦截器的详细说明,请参见文档

这篇关于Struts中的动作类执行流程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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