Java Struts 1.2(生命周期)中的控制流

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19512942/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 17:54:32  来源:igfitidea点击:

Flow of control in Struts 1.2 (Lifecycle)

javastrutsstruts-1struts-config

提问by Punjan Sudhar

Title may sound a little vague but I'll give it a go. I have 2 servlets:

标题可能听起来有点模糊,但我会试一试。我有 2 个 servlet:

  1. one.java:Extends the Action classforwards the page to success or failure based on the inputs at index.jsp
  2. two.java:Extends the ActionForm class, Has getters and setters method
  1. one.java:Action class根据输入扩展将页面转发到成功或失败index.jsp
  2. two.java:扩展了ActionForm class,有getter和setter方法

I have 3 jsp files:

我有3个jsp文件:

  1. index.jsp:Is the welcome pages and asks for a username combination
  2. success.jsp:Is called if the combination is correct
  3. failure.jsp:Is called if the combination is false
  1. index.jsp:是欢迎页面并要求输入用户名组合
  2. success.jsp:如果组合正确则调用
  3. failure.jsp:如果组合为假则调用

I have 2 xml files:

我有 2 个 xml 文件:

  1. web.xml:DD
  2. struts-config.xml:Struts config file
  1. web.xml:DD
  2. struts-config.xml:Struts 配置文件

I understand how web.xml works. My only doubt is, which one of the, one.java /two.javais called first from the struts.xml?

我了解 web.xml 是如何工作的。我唯一的疑问是,从 struts.xml 中首先调用one.java /two.java 中的哪一个?

I tried to debug and found out that the ActionFormclass i.e two.javais called first, then it returns the value to the Actioni.e one.java.

我尝试调试并发现ActionForm类 ietwo.java首先被调用,然后它将值返回给Actionie one.java

But isn't Action class is supposed to execute first,and then the action form ? I mean This is what MVC architecture follows.

但是不是应该先执行 Action 类,然后执行动作表单吗?我的意思是这就是 MVC 架构所遵循的。

Please explain. Links to a very highly detailed workflow would be really helpful.

请解释。指向非常详细的工作流程的链接将非常有帮助。

采纳答案by bsiamionau

It is not surprising that ActionFormclass is called before Action- Struts form should be filled with user's data before calling of Struts action method, any of which has 4 parameters:

ActionForm类在调用之前并不奇怪Action- Struts 表单应该在调用 Struts 操作方法之前填充用户的数据,其中任何一个都有 4 个参数:

ActionMapping actionMapping,
ActionForm actionForm,
HttpServletRequest request,
HttpServletResponse response

Second one - ActionForm- should be ready to allow furthest data processing. I've just found great sequence diagramto illustrate all Struts lifecycle stages:

第二个 - ActionForm- 应该准备好进行最远的数据处理。我刚刚找到了一个很好的序列图来说明所有 Struts 生命周期阶段:

enter image description here

在此处输入图片说明

In short:

简而言之:

  1. After getting client's request Struts front-controller calls RequestProcessorto find out appropriate action and form using struts-config.xml
  2. RequestProcessorgets Struts form object (or creates it if it doesn't exist), populates with data from request, initiates validation (if exists) and calls appropriate Struts action.
  3. Struts action performs all furthers necessary operations.
  1. 得到客户的请求后,Struts 前端控制器调用RequestProcessor使用struts-config.xml找出合适的动作和表单
  2. RequestProcessor获取 Struts 表单对象(或者如果它不存在则创建它),填充来自请求的数据,启动验证(如果存在)并调用适当的 Struts 操作。
  3. Struts action 执行所有进一步的必要操作。