At first in my web server I only had one REST servlet. Something like:
@Path("/")
public class Controller {
@GET
@Produces({ MediaType.TEXT_HTML })
public Response get(@Context UriInfo info) throws Exception {
...
}
@GET
@Path("resource1")
@Produces({ MediaType.TEXT_HTML })
public Response resource1() throws Exception {
...
}
...
}
And the web.xml:
<servlet>
<servlet-name>rest</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>xpto.mypack1;xpto.mypack2</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>rest</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
But then I wanted to add some static html to the server, so I updated the servlet mapping to /rest/*
and the @Path directive of Controller servlet class from "/" to "/rest". Everything works fine but the sub-resources or methods of controller with the @path directive that stopped working.. ie:
Any help? I already tried a list of combinations of / after and before each @Path directive, with no success... Many thanks
One update:
I used the trace util and got the following results:
for /[app-name]/rest (it works):
for /[app-name]/rest/resource1 (it doesn't work):
I hope it helps someone to help me..
If you define your servlet mapping as /rest/*
, don't repeat /rest
in the @Path
annotation of your resources. Ie all you need to do is keep the controller as is (in your question above) and just change the servlet mapping. The URL at which the resources are available is:
<application_context_path>/<servlet_mapping>
So, if you change the @Path
annotation from @Path("/")
to @Path("rest")
and you also change the servlet mapping to /rest
, then your resources would be available at:
<application_context_path>/rest/rest/*
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.