How do I pass multiple parameter in URL?

前端 未结 3 1309
猫巷女王i
猫巷女王i 2020-12-13 00:38

I am trying to figure out how to pass multiple parameters in a URL. I want to pass latitude and longitude from my android class to a java servlet. How can I do that?

3条回答
  •  渐次进展
    2020-12-13 01:03

    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.

提交回复
热议问题