struts控制器在读取struts-config.xml文件时创建动作对象吗?
“struts”是什么意思 控制器读取 struts-config.xml 文件” web应用程序启动了
是控制器创建动作对象 在阅读 struts-config 时 文件?
what does it means "struts
controller reads the
struts-config.xml file" when ever
web application is started?is controller create action objects
while reading the struts-config
file?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
当 struts 读入文件时,它只是解析它并加载操作定义。您将得到的唯一错误是 XML 解析错误。不确定 Struts 2,但在 Struts 1 中,它不会验证对象或转发的目标是否存在或编译。这是运行时检查
when struts reads in the file it is only parsing it and loading the action definitions. The only errors you will get are XML parsing errors. Not sure about Struts 2, but in struts 1 it will not validate that the objects or the forwarded targets exist or compile. That is a runtime check
我认为它是惰性执行的(当访问 URL 时)。至少Struts1 是这样。
I think it does that lazily (when the URL is accessed). At least Struts1 does.
1.当Web应用程序启动时,“struts控制器读取struts-config.xml文件”是什么意思?
“读取”意味着Struts将解析XML文件并创建您在其中声明的标签的对象表示(例如,ActionMapping 反映
标记)。每当 Struts 需要了解不同的配置信息时,就会使用这些对象,从而避免每次都需要执行昂贵的 I/O 操作来访问 XML 文件。包含解析文件规则的类是 org.apache.struts.config.ConfigRuleSet(javadoc:解析 Struts 配置文件 (struts-config.xml) 所需的 Digester 规则集) 。
2.控制器在读取 struts-config 文件时是否创建操作对象?
不,这是稍后在收到请求时完成的。
当收到请求时,Struts 会尝试查找与 URL 路径匹配的已存在的 Action 实例。如果找到它,它将返回它,否则它将创建它并存储它以供以后使用,然后再返回它。
RequestProcessor.processActionCreate
方法执行此操作(javadoc:返回一个 Action 实例,该实例将用于处理当前请求,必要时创建一个新请求)。1. what does it means "struts controller reads the struts-config.xml file" when ever web application is started?
The "read" means that Struts will parse the XML file and create object representations of the tags you have declared inside (e.g. the ActionMapping reflects an
<action>
tag). These objects will then be used whenever Struts needs to know different configuration information avoiding the need to do costly I/O operations to go to the XML file each time.The class that contains the rules for parsing the file is
org.apache.struts.config.ConfigRuleSet
(javadoc: The set of Digester rules required to parse a Struts configuration file (struts-config.xml)).2. is controller create action objects while reading the struts-config file?
No, this is done later, when a request comes in.
When a request comes in, Struts tries to find an already existing Action instance that matches the URL path. If it finds it, it returns it, else it will create it and store it for later use before returning it.
The
RequestProcessor.processActionCreate
method does this (javadoc: return an Action instance that will be used to process the current request, creating a new one if necessary).