简体   繁体   English

读取struts-config.xml文件时,struts控制器会创建动作对象吗?

[英]is struts controller creats the action objectes when reading struts-config.xml file?

  1. what does it means "struts controller reads the struts-config.xml file" when ever web application is started? Web应用程序启动时,“ struts控制器读取struts-config.xml文件”是什么意思?

  2. is controller create action objects while reading the struts-config file? 控制器在读取struts-config文件时是否创建动作对象?

when struts reads in the file it is only parsing it and loading the action definitions. 当struts读入文件时,它只是解析它并加载动作定义。 The only errors you will get are XML parsing errors. 您将获得的唯一错误是XML解析错误。 Not sure about Struts 2, but in struts 1 it will not validate that the objects or the forwarded targets exist or compile. 不确定Struts 2,但是在Struts 1中,它不会验证对象或转发的目标是否存在或编译。 That is a runtime check 那是运行时检查

is controller create action objects while reading the struts-config file 是控制器在读取struts-config文件时创建动作对象

I think it does that lazily (when the URL is accessed). 我认为这样做很懒(当访问URL时)。 At least Struts1 does. 至少Struts1可以。

1. what does it means "struts controller reads the struts-config.xml file" when ever web application is started? 1.启动Web应用程序时,“ struts控制器读取struts-config.xml文件”是什么意思?

The "read" means that Struts will parse the XML file and create object representations of the tags you have declared inside (eg the ActionMapping reflects an <action> tag). “读取”表示Struts将解析XML文件并创建您在其中声明的标签的对象表示形式(例如,ActionMapping反映了<action>标签)。 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. 每当Struts需要知道不同的配置信息时,就将使用这些对象,从而避免了每次都要执行昂贵的I / O操作来访问XML文件的麻烦。

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)). 包含解析文件规则的类是org.apache.struts.config.ConfigRuleSet (javadoc:解析Struts配置文件(struts-config.xml)所需的Digester规则集)。

2. is controller create action objects while reading the struts-config file? 2.控制器在读取struts-config文件时是否创建动作对象?

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. 收到请求时,Struts会尝试查找与URL路径匹配的现有Action实例。 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). RequestProcessor.processActionCreate方法执行此操作(javadoc:返回一个Action实例,该实例将用于处理当前请求,并在必要时创建一个新实例)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM