【问题标题】:Reduce URI path in REStful with Java (JAX-RS)使用 Java (JAX-RS) 减少 RESTful 中的 URI 路径
【发布时间】:2016-03-17 11:54:18
【问题描述】:

我是 java 新手,JAX-RS.i 已经为简单的应用程序开发了工作示例。

现在我想在 RESTFul 中减少我的网址

目前我有 http://localhost:8084/eshipper_api/apis/api/get_quote 这个网址。

它的工作和输出。

我想减少它并希望让它像 http://localhost:8084/eshipper_api/apis/get_quote

我的 web.xml

     <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
         version="3.1">
         <servlet>
           <servlet-name>Eshipper API Application</servlet-name>
           <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
              <init-param>
                 <param-name>jersey.config.server.provider.packages</param-name>
                 <param-value>com.eshipper.client.request</param-value>
              </init-param>
           </servlet>
        <servlet-mapping>
        <servlet-name>Eshipper API Application</servlet-name>
           <url-pattern>/apis/*</url-pattern>
        </servlet-mapping>  
     </web-app>

/java/com/eshipper/client/request/RequestHandler.java 中的代码,这是com.eshipper.client.request 的参数值

        @Path("api")
        public class RequestHandler 
        {
           @GET
           @Path("/get_quote")
           public String GetQuote()
           {
               return "GOdddd Working";
           }
        }

请帮助我。 提前致谢。

【问题讨论】:

    标签: java apache rest jax-rs web.xml


    【解决方案1】:

    将您的 @Path("api") 更改为 @Path("")

        @Path("")
        public class RequestHandler 
        {
           @GET
           @Path("/get_quote")
           public String GetQuote()
           {
               return "GOdddd Working";
           }
        }
    

    或者,您可以将 web.xml 更改为:

    &lt;url-pattern&gt;/*&lt;/url-pattern&gt; 并设置您的@Path("/apis"),它会做同样的事情。

    你有你的http://servername/上下文/web.xml servlet路径/类注释路径/方法注释路径

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-09-02
      • 2011-06-14
      • 1970-01-01
      • 2014-10-03
      • 1970-01-01
      • 1970-01-01
      • 2017-09-08
      相关资源
      最近更新 更多