为什么 web.xml 从 servlet 3.0 中删除 [英] Why web.xml is removed from servlet 3.0

查看:37
本文介绍了为什么 web.xml 从 servlet 3.0 中删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么 web.xml 从 servlet 3.0 中删除?现在配置是通过 Java 完成的.

Why was web.xml removed from servlet 3.0 ?, and the configuration is now done through Java.

推荐答案

在 Servlet 3.0 中没有删除对 web.xml 的支持,并且(IMO)在可预见的未来不太可能删除它.

Support for web.xml was NOT removed in Servlet 3.0, and (IMO) it is unlikely to be removed in the foreseeable future.

证据?如果您下载 Servlet 3.0 规范并搜索web.xml",您将看到大量对它的引用.

Evidence? If you download the Servlet 3.0 spec and search for "web.xml", you will see lots of references to it.

最有说服力的报价在A6.6

The most cogent quote is in A6.6

"Web 应用程序不需要包含 web.xml,如果它不包含任何Servlet、过滤器或侦听器组件.换句话说,一个应用程序只包含静态文件或 JSP 页面不需要存在 web.xml."

"A web application is NOT required to contain a web.xml if it does NOT contain any Servlet, Filter, or Listener components. In other words an application containing only static files or JSP pages does not require a web.xml to be present."

它的意思是,一个 web 应用程序允许省略web.xml"文件......但它也被允许包含一个.换句话说,它是可选的.

What it is saying is that a webapp is permitted to leave out the "web.xml" file ... but it is also permitted to include one. In other words, it is optional.

那么为什么他们允许您忽略web.xml"?我能想到几个原因:

So why did they allow you to leave out "web.xml"? I can think of a couple of reasons:

  • 以编程方式或通过这种方式通过注释进行配置通常更方便!

以不同的方式/地点进行配置是违反 DRY 原则的.如果您可以通过注释和/或显式调用在 Java 源代码中进行配置,为什么还要在 XML 中进行配置?

It is a violation of DRY principles to be doing configuration in different ways / places. If you can do the configuration in the Java source code via annotations and/or explicit calls, why do it in XML as well?

但最重要的是,这是您的选择.

这篇关于为什么 web.xml 从 servlet 3.0 中删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆