Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

I am deploying on Jetty 9.1.x (but I think this question is not container specific).

My web.xml file is quite old and declares itself as a Servlet 2.4 application:

<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 seem to work correctly.

Since I am using 3.0 features, I would like to change the declaration to be correct:

<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.

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?

like image 483
Jen S. Avatar asked Jan 27 '14 14:01

Jen S.


People also ask

What is the use of WEB xml file in servlet?

web. xml defines mappings between URL paths and the servlets that handle requests with those paths. The web server uses this configuration to identify the servlet to handle a given request and call the class method that corresponds to the request method.

What is Web app in xml?

Web applications are configured with the <web-app> tag, which can occur in a number of places. WEB-INF/web. xml contains a top-level web-app element. It is the Servlet standard location for defining things like servlet mappings and security roles.

What is servlet and servlet mapping in WEB xml?

Servlet mapping specifies the web container of which java servlet should be invoked for a url given by client. It maps url patterns to servlets. When there is a request from a client, servlet container decides to which application it should forward to. Then context path of url is matched for mapping servlets.

What is the use of WEB xml in Spring MVC?

Spring MVC web applications use the web. xml file as a deployment descriptor file. Also, it defines mappings between URL paths and the servlets in the web.


1 Answers

You should be able to simply swap the schema declaration from 2.4 to 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.

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.

However xsd schema for 3.0 is smaller then 1/3rd of the other two versions. Not sure how to proceed in this case (any ideas welcome!)


You can download all schemas from here and do the comparison yourself:

  • web xml v2.4 xsd schema
  • web.xml v2.5 xsd schema
  • web.xml v3.0 xsd schema


Not so scientific method

Here are the what's new articles describing each new version of the standard:

  • What's new in Servlet 2.4
  • What's new in Servlet 2.5
  • What's new in Servlet 3.0

If you read in, the changes to web.xml descriptor mentioned in the articles are minute.

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.

Hope this helps!

like image 120
diginoise Avatar answered Oct 26 '22 10:10

diginoise