I’ve just started building my own rest webservice and I started off by going through this excellent tutorial: http://www.vogella.com/articles/REST/article.html#first_project
However there is something that I don’t quite understand. It has to do with the path to the service.
The path is now this for the hello resource:
http://localhost:8080/de.vogella.jersey.first/rest/hello
This is default from the tutorial.
However i would like to change this to a more convenient link, for example like this:
http://localhost:8080/mywebservice/resources/hello
I change the web.xml to the following as a try to achieve it:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>mywebservice</display-name>
<servlet>
<servlet-name>Jersey REST Service</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>de.vogella.jersey.first</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey REST Service</servlet-name>
<url-pattern>/resources/*</url-pattern>
</servlet-mapping>
</web-app>
I changed the display name and the url-pattern but it has no effect. I cant get to the resource using the path I want it to be, though I can retrieve it from the old path.
Why is that? Does the displayname from the web.xml got nothing to do with this?
You are changing the context name of the Webapp. If you’re deploying it in the form of a war (webapp archive), the name of the war would be the context name.
In the example you’re following, you’re creating a Dynamic Web project with that name. You’ll have to rename it suitably.