【问题标题】:Jersey Path resolution泽西路径分辨率
【发布时间】:2012-06-28 06:05:39
【问题描述】:

这是我的 Jersey 服务,我使用 url 访问该服务

http://host:port/contextroot/welcome/data

当我将 Jersey servlet 映射到 /welcome/* 时,我收到 404 错误。但是当我在 web.xml 中说 /* 时,我的请求会顺利通过。我不希望我的 webapp 中的所有请求都通过球衣。如何将路径限制为仅使用 /welcome 的请求?

@Path("/welcome")
public class WelcomeRestJson {

    @POST
    @Path("/data")
    @Produces("text/plain")
    @Consumes("application/json")

    public String processPostData(MyObject myObject) {
        System.out.println("Inside processPostData");
        return "success";
    }

}

【问题讨论】:

    标签: java web-services jakarta-ee jersey


    【解决方案1】:

    当将 servlet 映射到 /welcome/* 时,只需将根资源 (WelcomeRestJson) 的路径模板从 @Path("/welcome") 更改为 @Path("/") - 这样相同的 URL (@987654321 @) 将像以前一样工作。

    【讨论】:

      【解决方案2】:

      映射到 web.xml 中的 /welcome/*:

      <servlet>
          <servlet-name>ServletAdaptor</servlet-name>
          <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
      </servlet>
      <servlet-mapping>
          <servlet-name>ServletAdaptor</servlet-name>
          <url-pattern>/welcome/*</url-pattern>
      </servlet-mapping>
      

      然后您可以在 /welcome 下调用您的 web 服务,其余的请求在不同的路径上。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-07-17
        • 1970-01-01
        • 2013-04-06
        • 1970-01-01
        • 2014-11-04
        • 2013-02-03
        • 2014-07-16
        • 1970-01-01
        相关资源
        最近更新 更多