Does encodeURICOmponent work in js?
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++
开发者_Go百科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.
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.
精彩评论