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
Flow of control in Struts 1.2 (Lifecycle)
提问by Punjan Sudhar
Title may sound a little vague but I'll give it a go. I have 2 servlets:
标题可能听起来有点模糊,但我会试一试。我有 2 个 servlet:
- one.java:Extends the
Action class
forwards the page to success or failure based on the inputs atindex.jsp
- two.java:Extends the
ActionForm class
, Has getters and setters method
- one.java:
Action class
根据输入扩展将页面转发到成功或失败index.jsp
- two.java:扩展了
ActionForm class
,有getter和setter方法
I have 3 jsp files:
我有3个jsp文件:
- index.jsp:Is the welcome pages and asks for a username combination
- success.jsp:Is called if the combination is correct
- failure.jsp:Is called if the combination is false
- index.jsp:是欢迎页面并要求输入用户名组合
- success.jsp:如果组合正确则调用
- failure.jsp:如果组合为假则调用
I have 2 xml files:
我有 2 个 xml 文件:
- web.xml:DD
- struts-config.xml:Struts config file
- web.xml:DD
- 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 ActionForm
class i.e two.java
is called first, then it returns the value to the Action
i.e one.java
.
我尝试调试并发现ActionForm
类 ietwo.java
首先被调用,然后它将值返回给Action
ie 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 ActionForm
class 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 生命周期阶段:
In short:
简而言之:
- After getting client's request Struts front-controller calls
RequestProcessor
to find out appropriate action and form using struts-config.xml RequestProcessor
gets 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.- Struts action performs all furthers necessary operations.
- 得到客户的请求后,Struts 前端控制器调用
RequestProcessor
使用struts-config.xml找出合适的动作和表单 RequestProcessor
获取 Struts 表单对象(或者如果它不存在则创建它),填充来自请求的数据,启动验证(如果存在)并调用适当的 Struts 操作。- Struts action 执行所有进一步的必要操作。