How do I pass multiple parameter in URL?
This
url = new URL("http://10.0.2.2:8080/HelloServlet/PDRS?param1="+lat+"¶m2="+lon);
must work. For whatever strange reason1, you need ?
before the first parameter and &
before the following ones.
Using a compound parameter like
url = new URL("http://10.0.2.2:8080/HelloServlet/PDRS?param1="+lat+"_"+lon);
would work, too, but is surely not nice. You can't use a space there as it's prohibited in an URL, but you could encode it as %20
or +
(but this is even worse style).
1 Stating that ?
separates the path and the parameters and that &
separates parameters from each other does not explain anything about the reason. Some RFC says "use ? there and & there", but I can't see why they didn't choose the same character.
I do not know much about Java but URL query arguments should be separated by "&", not "?"
https://www.rfc-editor.org/rfc/rfc3986 is good place for reference using "sub-delim" as keyword. http://en.wikipedia.org/wiki/Query_string is another good source.
You can pass multiple parameters as "?param1=value1¶m2=value2
"
But it's not secure. It's vulnerable to Cross Site Scripting (XSS) Attack
.
Your parameter can be simply replaced with a script.
Have a look at this article and article
You can make it secure by using API of StringEscapeUtils
static String escapeHtml(String str)
Escapes the characters in a String using HTML entities.
Even using https
url for security without above precautions is not a good practice.
Have a look at related SE question:
Is URLEncoder.encode(string, "UTF-8") a poor validation?