Struts2:为什么要扩展ActionSupport类?
我是 Struts2 的初学者。请告诉我为什么要扩展 ActionSupport
类? (当不需要验证或国际化时)
扩展 ActionSupport
类是否还有其他好处?
I am a beginner to Struts2. Please tell me why to extend ActionSupport
class? (When one doesn't have the requirement of validation or internationalization)
Are there any other benefits provided by extending ActionSupport
class?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
方便地访问基本的常用功能。
它具有常用方法的默认实现(例如,
execute()
、input()
),提供对Action.SUCCESS
和其他结果名称的访问 请注意,I18N 功能不仅仅是简单的翻译,还包括一些格式设置,允许非程序员提供标签/文本等。
很少(曾经?)有充分的理由不延长它。即使是 REST 插件操作(例如处理 JSON 端点的操作)也经常使用验证和 I18N 支持。
Convenience and access to basic, common functionality.
It has default implementations of common methods (e.g.,
execute()
,input()
), gives access toAction.SUCCESS
and other result names, etc.Note that the I18N functionality goes a bit beyond simple translation, but includes some formatting, allows non-programmers to provide labels/texts, and so on.
There's rarely (ever?) a good reason not to extend it. Even REST plugin actions, e.g., those that handle JSON endpoints, often use validation and I18N support.
如果你不想使用 struts2 提供的开箱即用功能,你总是可以避免使用 ActionSupport 类。
这基本上是一个帮助器类,它为你提供了许多开箱即用功能,但同时 Struts2 框架不要求要使用此类,它所需要的只是您的操作类的入口方法,其返回类型为 String ,并且
除了验证或国际化之外,该方法还可以抛出常规异常 此类还提供许多其他功能,例如动作级别错误等。
请参阅文档了解详细信息
ActionSupport
IF you don't want to use out of the box features provided by the struts2 you can always avoid using ActionSupport class
This is basically a helper class which provides many out of the box features for you, but at same time Struts2 framework do not ask to use this class, all it want is an entry method for your action class with return type as
String
and which can throw a generalException
beside validation or Internationalization this class also provides many other features like Action level Errors etc.
Follow the documentation for detail
ActionSupport