简体   繁体   English

web.xml中与Servlet 3.0兼容的web-app声明有什么作用?

[英]What does a Servlet 3.0 compatible web-app declaration in web.xml do?

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. 我的配置实际上声明了一些仅Servlet 3.0的功能,比如默认的错误页面。 These features do not validate according to the schema, but the features seem to work correctly. 这些功能不会根据架构进行验证,但功能似乎可以正常工作。

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? 更改声明是否会影响Jetty的运行时行为? Does Jetty treat a 2.4 app somehow differently than a 3.0 app? Jetty对待2.4应用程序的方式与3.0应用程序不同吗?

You should be able to simply swap the schema declaration from 2.4 to 3.0 . 您应该能够简单地将架构声明从2.4交换到3.0

Scientific method 科学的方法

Initially I set off to prove it by doing diff between 2.4 and 2.5 and another one comparing 2.5 and 3.0 . 最初我开始通过在2.42.5之间进行diff来证明它,并且另一个比较2.53.0

I have convinced myself that the differences between 2.4 and 2.5 are only additive and the name space have shifted from j2ee to javaee . 我已经说服自己, 2.42.5之间的差异只是附加的,名称空间已从j2ee转移到javaee

However xsd schema for 3.0 is smaller then 1/3rd of the other two versions. 但是3.0的 xsd架构比其他两个版本的1/3小。 Not sure how to proceed in this case (any ideas welcome!) 在这种情况下不确定如何处理(欢迎任何想法!)


You can download all schemas from here and do the comparison yourself: 您可以从此处下载所有模式并自行进行比较:


Not so scientific method 不是那么科学的方法

Here are the what's new articles describing each new version of the standard: 以下是描述该标准的每个新版本的新文章:

If you read in, the changes to web.xml descriptor mentioned in the articles are 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! 希望这可以帮助!

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

相关问题 将目录添加到我的 servlet web-app web.xml - adding directory to my servlet web-app web.xml Maven:自定义web-app项目的web.xml - Maven: Customize web.xml of web-app project 使用Java web-app(web.xml)部署数据库配置(用户名/密码)的最佳做法是什么? - What is the best practice to deploy database config (username/password) with Java web-app (web.xml)? java,tomcat:web.xml中的web-app标签中id属性的含义是什么? - java, tomcat: what is the meaning of the id attribute in the tag web-app in web.xml? 你如何在你的<web-app> web.xml 中的标签?</web-app> - How do you specify the root context in your <web-app> tags in web.xml? 为什么我们必须指定 <web-app> 在web.xml文件中标记? - Why do we have to specify attributes of the <web-app> tag in the web.xml file? 为什么Maven寻找`webapp \\ WEB-INF \\ web.xml`而不是`web-app \\ WEB-INF \\ web.xml` - Why is maven looking for `webapp\WEB-INF\web.xml` instead of `web-app\WEB-INF\web.xml` 嵌入式Servlet 3.0容器使用ServletContainerInitializer而不是web.xml - Embedded Servlet 3.0 container to use ServletContainerInitializer instead of web.xml 没有web.xml错误的Servlet 3.0-页面javaconfig - Servlet 3.0 without web.xml error-page javaconfig Servlet3.0环境中的web.xml文件在哪里? - Where is the web.xml file in Servlet3.0 enviroment?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM