Can I use servlet api 3.0 and jetty 8?

user2029910 picture user2029910 · Jan 31, 2013 · Viewed 12.2k times · Source

I want to use 3.0 servlet-api with Jetty 8. Currently 2.4 servlet-api is defined in my web.xml. And in the webdefault.xml 2.5 servlet-api is defined. Someone else set this up so they very well might have done something wrong. Which servlet-api version am I actually using? 2.4 or 2.5? I have 3.0 already in my classpath. What do I need to change in web.xml and/or webdefault.xml to get it working?

Thank you in advance.

Answer

BalusC picture BalusC · Jan 31, 2013

You normally don't provide the Servlet API yourself. This is normally to be provided by the target servletcontainer itself. Examples of Servlet 3.0 compatible containers are Tomcat 7.x, Glassfish 3.x, JBoss AS 6.x/7.x and, yes, Jetty 8.x.

You just have to declare the <web-app> root element of web.xml to comply the highest version as supported by the target container.

<?xml version="1.0" encoding="UTF-8"?>
<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">

</web-app>

See also: