Reputation: 3
I am using Jersey with tomacat 6 and eclipse Juno.
my file name is HelloWorldService :
package com.mkyong.rest;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.Response;
@Path("/hello")
public class HelloWorldService {
@GET
@Path("/{param}")
public Response getMsg(@PathParam("param") String msg) {
String output = "Jersey say : " + msg;
return Response.status(200).entity(output).build();
}
}
Web.xml:
<web-app id="WebApp_ID" 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">
<display-name>Restful Web Application</display-name>
<servlet>
<servlet-name>jersey-serlvet</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.mkyong.rest</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>jersey-serlvet</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
when i am running my project using Apache as server- it is going to this url:
http://localhost:8080/Test/WEB-INF/classes/com/mkyong/rest/HelloWorldService.java
and i am getting 404 error.
I also tried with version="3.0" and it didn't work. Please help me out.
Upvotes: 0
Views: 3748
Reputation: 3646
The address for your example would be:
http://localhost:8080/Test/rest/hello/stranger
and this would output:
Jersey say : stranger
P.S. I guess your WAR name is Test.war and because that your deploy path is localhost:8080/Test
Upvotes: 0
Reputation: 2297
you should give your url as follows;
http://localhost:8080/<your-war-name>/rest/hello/<your-param>
Upvotes: 3