Java web.xml 中与 Servlet 3.0 兼容的 web-app 声明有什么作用?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21383734/
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
What does a Servlet 3.0 compatible web-app declaration in web.xml do?
提问by Jen S.
I am deploying a web application that is declared in web.xml and deployed as a .war file.
我正在部署一个在 web.xml 中声明并部署为 .war 文件的 Web 应用程序。
I am deploying on Jetty 9.1.x (but I think this question is not container specific).
我正在 Jetty 9.1.x 上部署(但我认为这个问题不是特定于容器的)。
My web.xml file is quite old and declares itself as a Servlet 2.4 application:
我的 web.xml 文件很旧,并声明自己是一个 Servlet 2.4 应用程序:
<web-app version="2.4" id="my_app"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
My configuration actually declares some Servlet 3.0 only features, like a default error page. These features do not validate according to the schema, but the features seemto work correctly.
我的配置实际上声明了一些仅限 Servlet 3.0 的功能,例如默认错误页面。这些功能不会根据架构进行验证,但这些功能似乎可以正常工作。
Since I am using 3.0 features, I would like to change the declaration to be correct:
由于我使用的是 3.0 功能,因此我想将声明更改为正确的:
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
But I am scared to do this because I don't understand what the difference will be to Jetty.
但我害怕这样做,因为我不明白这对 Jetty 会有什么不同。
Will changing the declaration have any effect on the runtime behavior of Jetty? Does Jetty treat a 2.4 app somehow differently than a 3.0 app?
更改声明是否会对 Jetty 的运行时行为产生任何影响?Jetty 对待 2.4 应用程序的方式是否与 3.0 应用程序有所不同?
回答by diginoise
You should be able to simply swap the schema declaration from 2.4to 3.0.
您应该能够简单地将架构声明从2.4交换到3.0。
Scientific method
科学的方法
Initially I set off to prove it by doing diff
between 2.4and 2.5and another one comparing 2.5and 3.0.
最初,我开始通过diff
在2.4和2.5之间进行以及另一个比较2.5和3.0来证明这一点。
I have convinced myself that the differences between 2.4and 2.5are only additive and the name space have shifted from j2ee
to javaee
.
我说服自己,之间的差别2.4和2.5只是添加剂的名称空间已从转移j2ee
至javaee
。
Howeverxsd schema for 3.0is smaller then 1/3rd of the other two versions. Not sure how to proceed in this case (any ideas welcome!)
然而,3.0 的xsd 架构比其他两个版本的 1/3 小。不知道在这种情况下如何进行(欢迎任何想法!)
You can download all schemas from here and do the comparison yourself:
您可以从这里下载所有模式并自己进行比较:
Not so scientific method
不太科学的方法
Here are the what's newarticles describing each new version of the standard:
以下是描述该标准每个新版本的新文章:
If you read in, the changes to web.xml
descriptor mentioned in the articlesare minute.
如果你仔细阅读,文章中提到的web.xml
描述符的变化很小。
What I would do is simply list all the elements in your original web.xml
and confirm that they do exist in this document describing the 3.0 schema.
我要做的只是列出原始web.xml
文件中的所有元素,并确认它们确实存在于描述3.0 架构的文档中。
Hope this helps!
希望这可以帮助!