问题
I am learing jersey,below is my program where the output should come like this 8-6-1990 but it is displaying 0-0-0.I dont know the actual reason,can anyone help me
Multipleparam.java
package com.rest;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.Response;
@Path("multi")
public class Multipleparam {
@GET
@Path("{day}/{month}/{year}")
public Response getUserHistory(@PathParam("{day}") int day,
@PathParam("{month}") int month, @PathParam("{year}") int year) {
return Response.status(200).entity(day + "-" + month + "-" + year).build();
}
}
web.xml
<web-app>
<display-name>Archetype Created Web Application</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>com.rest</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey REST Service</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>
I am passing this in browser "http://localhost:9000/SingleParam/rest/multi/8/6/1990"
I just want to know where is the mistake and why it is displaying zeros ?
回答1:
Pass pathparm parameter name without bracket.
package com.rest;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.Response;
@Path("multi")
public class MultipleParam
{
@GET
@Path("{day}/{month}/{year}")
public Response getUserHistory(@PathParam("day") int day, @PathParam("month") int month,
@PathParam("year") int year)
{
return Response.status(200).entity(day + "-" + month + "-" + year).build();
}
}
来源:https://stackoverflow.com/questions/24994599/expected-output-is-not-displaying