预期输出未显示

时间:2014-07-28 11:48:50

标签: java jax-rs jersey-2.0

我正在学习球衣,下面是我的程序,输出应该像这样8-6-1990,但它显示0-0-0。我不知道实际原因,任何人都可以帮助我

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>

我在浏览器"http://localhost:9000/SingleParam/rest/multi/8/6/1990"中传递此内容 我只是想知道错误在哪里以及为什么显示零?

1 个答案:

答案 0 :(得分:0)

不带括号传递pathparm参数名称。

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();
    }
}