2016-03-17 10 views
-1

我是java的新手,JAX-RS.i已經開發了簡單應用程序的工作示例。使用Java減少URI的路徑(JAX-RS)

現在我想在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 /客戶機/ request/RequestHandler.java這是參數值爲com.eshipper.client.request

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

請幫我這個。 在此先感謝。

回答

2

更改@Path("api")@Path("")

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

或者,你可以改變你的web.xml中:

<url-pattern>/*</url-pattern>和設置您的@Path("/apis"),它會做同樣的事情。

你有你的http://servername/方面/web.xml中servlet路徑/類註釋路徑/註釋的方法路徑