Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java web app - What determines my Servlet API version? Does it get specified in web.xml?

Tags:

I'm using Eclipse EE Juno and my current web application is using Dynamic web modules 2.4. I'm trying to bump the version up to 3.0 but for some reason I'm unable to. when I try to change the version in project facets I get Cannot change version of project facet Dynamic Web Module to 3.0. Is it possible that there some bunk line in my web.xml file that determines this? How do I change the Dynamic web modules version if not from Eclipse project facet setting alone?

like image 654
stackoverflow Avatar asked Aug 27 '12 17:08

stackoverflow


People also ask

How do I know my servlet API version?

An Java EE application server is a concrete implementation of the JSP/Servlet API's. The highest supported Servlet/JSP API version is to be found in the specs/docs of the appserver used. The actually used Servlet API version is to be found in the web. xml root declaration.

What do we declare in WEB xml?

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. For example: the doGet() method for HTTP GET requests.

How do I map a servlet in WEB xml?

To map a URL to a servlet, you declare the servlet with the <servlet> element, then define a mapping from a URL path to a servlet declaration with the <servlet-mapping> element.

Which tags are used to register a servlet in WEB xml?

Your servlet name Registration should be same on both tags <servlet>... </servlet> and <servlet-mapping>... </servlet-mapping> and also package name should be same where your servlet class is located.


1 Answers

Servlet 2.4 in web.xml:

<web-app version="2.4"   xmlns="http://java.sun.com/xml/ns/j2ee"   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"> 

Servlet 3.0 in web.xml:

<web-app version="3.0"   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"> 

That's the only difference. The rest is your IDE configuration. In order to use Servlet 3.0 you must have 3.0 JARs on the CLASSPATH so that new annotations and other classes are available. But do not include servlet JAR in your WAR, the implementation should come from the servlet container.

like image 96
Tomasz Nurkiewicz Avatar answered Oct 01 '22 08:10

Tomasz Nurkiewicz