RESTful Web Services Developer's Guide

Configuring the Resource with the Runtime

The helloworld-webapp/src/main/webapp/WEB-INF/web.xml deployment descriptor for HelloWorld-Webappcontains the settings for configuring your resource with the JAX-RS API runtime:

<servlet>
     <servlet-name>Jersey Web Application</servlet-name>
     <servlet-class>
         com.sun.jersey.spi.container.servlet.ServletContainer
     </servlet-class>
			<init-param>
					<param-name>
							com.sun.jersey.config.property.packages
					</param-name>
					<param-value>
							com.sun.jersey.samples.helloworld.resources
					</param-value>
			</init-param>
			<load-on-startup>1</load-on-startup>
	</servlet>
<servlet-mapping>
     <servlet-name>Jersey Web Application</servlet-name>
	     <url-pattern>/*</url-pattern>
</servlet-mapping>

The com.sun.jersey.spi.container.servlet.ServletContainer servlet is part of the JAX-RS API runtime, and works with the generated HelloWorldResource class to get the resources provided by your application. The <servlet-mapping> elements specify which URLs your application responds to relative to the context root of your WAR. Both the context root and the specified URL pattern prefix the URI Template specified in the @Path annotation in the resource class file. In the case of the HelloWorld-WebApp sample application, @Path is set to /helloworld, the URL pattern is set to the wild card character, and the context root specified in sun-web.xml is /helloworld-webapp, so the resource will respond to requests of the form:


http://<server>:<server port>/helloworld-webapp/helloworld