[英]how to encode and decode url in path string in java
我有這樣的要求,即我需要在Ajax中發送一個URL,並且該URL是/ somehost / users / {userid} / feed / {feedurl},其中userid和feedurl是路徑參數,將在使用Rest Frame編寫的servlet中接受。
我的Ajax電話是
$.ajax({
url : "/somehost/users/1/feeds/"+encodeURIComponent("**Please Think
that i passing a valid URL here**")),
type : "DELETE",
/*contentType: 'Content-type: text/plain; charset=iso-8859-1',*/
data : {feed_url : tr.attr("value")},
....
....
....
)};
我的servlet是
@Path(“ / users”)
公共類UserServlet {
@DELETE
@Path("{user_id}/feeds/{feed_url}")
@Produces(MediaType.APPLICATION_JSON)
public String deletefee(
@PathParam("feed_url") String feedId,
@PathParam("user_id") @DefaultValue("1") String userId) {
System.out.println("I am in UserServlet delete");
}
}
現在我無法打我的servlet。
我想知道如何將URL作為@pathparam發送到我的servlet。
如果您將額外的斜杠添加到“ / somehost / users / 1 / feeds”,使其變為“ / somehost / users / 1 / feeds /”,那么這行得通嗎?
當前,您正在訪問類似“ / somehost / users / 1 / feeds1”的URI,而不是“ / somehost / users / 1 / feeds / 1”
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.