0
比方說,我設置以下的球衣資源:如何獲取Jersey中傳入URL的路徑值?
@Path("/blah")
public class BlahResource {
@GET
@Path("/")
public String printRelativeUrlPath()
{
System.out.println("I want to print the relative path that lands us in this method");
System.out.println("For Ex: /do/1/then/2");
System.out.println("For Ex: /wait/3/then/4");
System.out.println("For Ex: /done/5/done/6");
}
}
我希望能夠打印出達到這一方法相對URL路徑,爲前:
- GET
http://somehost/blah/do/1/then/2
應打印/do/1/then/2
- GET
http://somehost/blah/wait/3/then/4
應打印/wait/3/then/4
- GET
http://somehost/blah/done/5/done/6
應打印/done/5/done/6
當我使用澤西島時,如何獲取此信息?
確定這是要健全愚蠢的,但我按下熱鍵自動整理並給予我目前的Maven + JAR +依賴性設置...它不能找到HttpServletRequest的導入!我環視了一番,傳遞了'@Context UriInfo allUri'作爲參數,然後評估它爲'System.out.println(allUri.getPath());'做到了! – pulkitsinghal 2013-02-14 19:35:14