encodeURICOmponent 在 js 中工作吗?
我有名为 booksearch.js 和 admin.java 的文件。我需要将 uri 值从 booksearch.js 传递到 admin.java。 uri 的值具有特殊字符“+”,因此我在 booksearch.js 中使用了encodeURIComponent。我在警报框中警告了 uri,并且在encodeURIComponent 之后,uri 的值已正确编码。但是当我使用 getParameter() 函数将此编码值传递给 admin.java 时。 uri 的值没有“+”号。
我在这里做错了什么?
booksearch.js 的代码是
function editBook(uri, properties){
var params = "";
for (var property in properties[0])
params += "&" + property + "=" + properties[0][property];
alert("This is the uri "+uri);
uri=encodeURIComponent(uri);
alert("The new uri is "+uri);
$.ajax({
url: "Admin?action=edit&uri=" + uri + params,
dataType: "html",
success: function(response){
$("#output").append(response);
}
});
}
admin.java 中的代码是
if (action.equals("edit")) {
String uri = request.getParameter("uri");
System.out.println("this is the uri of the new book added "+uri);
输出是
在我得到的 uri 的第一个警报框中
这是 uri http://protege.stanford.edu/kb#BestSeller
新 uri 为 http://protege.stanford.edu/kb#BestSeller 在 C++ 中
getparameter 之后我得到输出,因为
这是添加的新书的 uri http://protege.stanford.edu/kb#BestSeller in C
发生了什么?
问候,
阿尔卡纳。
I have files by name booksearch.js and admin.java. I need to pass a value of uri from booksearch.js to admin.java. The value of uri has the special character '+' so I did use encodeURIComponent in booksearch.js. I alerted the uri in an alert box and after encodeURIComponent the value of uri was encoded properly. But when I pass this encoded value to admin.java by using getParameter() function. The value of uri does not have the '+' sign.
What have I done wrong here?
The code of booksearch.js is
function editBook(uri, properties){
var params = "";
for (var property in properties[0])
params += "&" + property + "=" + properties[0][property];
alert("This is the uri "+uri);
uri=encodeURIComponent(uri);
alert("The new uri is "+uri);
$.ajax({
url: "Admin?action=edit&uri=" + uri + params,
dataType: "html",
success: function(response){
$("#output").append(response);
}
});
}
The code in admin.java is
if (action.equals("edit")) {
String uri = request.getParameter("uri");
System.out.println("this is the uri of the new book added "+uri);
The output is
In the first alert box of uri I get
This is the uri http://protege.stanford.edu/kb#BestSeller in C++
The new uri is http://protege.stanford.edu/kb#BestSeller in C++
after getparameter I get the output as
this is the uri of the new book added http://protege.stanford.edu/kb#BestSeller in C
What is happening?
Regards,
Archana.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你在这里没有做错什么。
getParameter()
只是将值 URL 解码回其正常形式。如果您想要原始(URL 编码)查询字符串,请使用
request.getQueryString()
。您只需要自己在进一步的参数中解析它即可。You're doing nothing wrong here. The
getParameter()
just URL-decodes the values back to their normal forms.If you rather want the raw (URL-encoded) query string, use
request.getQueryString()
. You only need to parse it in further parameters yourself.