需要用XML来排列吗?
我对声明元素中的排列感到困惑。 写有什么区别吗?
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/web-application-context.xml
</param-value>
</context-param>
如果我这样写:或者这样
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/web-application-context.xml
</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
I am confused with arrangement in the declaration Elements. Is there any difference if I write like this:
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/web-application-context.xml
</param-value>
</context-param>
Or like this?
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/web-application-context.xml
</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是和否:
yes - 某些元素(如
)的顺序是相关的,因为它会改变实际过滤器的顺序应用。web.xml
的架构还定义了各种元素的顺序。否 - 其他元素的顺序无关,例如声明
的顺序。此外,在您的示例中,它没有任何区别。Yes and no:
yes - the order of some elements like
<filter-mapping/>
is relevant, as it will change the order of actual filters being applied. Also the schema forweb.xml
defines the order of various elements.no - the order of other elements is irrelevant, e.g. the order in which you declare
<servlet/>
s. Also in your example it doesn't make any difference.不会有任何区别,您可以按任何顺序编写,只要您始终使用正确的标签打开和关闭即可。
There won't be any difference, you can write in any order, provided you always open and close with proper tags.