2013-03-18 185 views
0

我正在使用Jersey開發REST服務。在一個PUT方法中,我想要使用一個字符串,然後在另一個方法中使用它。使用PUT方法發送字符串

是這樣的:我在「內容」字段中輸入一個字符串(TEST REST Web服務頁面),然後我使用該字符串在註銷方法:

@PUT 
@Path("logout") 
@Produces({"application/json", "text/plain"}) 
@Consumes(**xxxxx**) 
public String logout(**xxxxx**) throws Exception 
{ 
    String reponse = null; 
    reponse = new UserManager().logout(**xxxxx**); 
    return reponse; 
} 

所以,我想知道要在** xxxxx **字段中放置什麼。

謝謝!

回答

1

只需使用String參數。 JAX-RS運行時會將請求主體放入其中。

@PUT 
@Path("logout") 
@Produces({"application/json", "text/plain"}) 
public String logout(String data) throws Exception { 
    String response = null; 
    reponse = new UserManager().logout(data); 
    return response; 
} 

應該定義@Consumes是任何你想要的內容類型,以允許客戶端能夠發送,或離開它完全接受任何內容類型。

+0

是的,我剛剛嘗試過,並且工作;) – user2144555 2013-03-18 16:08:10

+0

太好了,隨時可以接受這個答案,如果它對你有幫助。祝好運與項目的其餘部分。 – Perception 2013-03-18 16:09:30

+0

謝謝。我在想我需要某種註解。 – user2144555 2013-03-18 16:13:42