Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,872 questions

51,796 answers

573 users

How to encode URL with query string parameters in Java

2 Answers

0 votes
import java.net.URLEncoder;

public class MyClass {
    public static void main(String args[]) throws Exception {
        String param = "web+hosting";

        String encodedParam = URLEncoder.encode(param, "UTF-8");

        String url = "https://seek4info.com/search.php?" + "query=" + encodedParam;

        System.out.println(url);
    }
}
   
   
   
   
/*
run:
    
https://seek4info.com/search.php?query=web%2Bhosting
    
*/

 



answered Nov 20, 2023 by avibootz
0 votes
import java.net.URLEncoder;

public class MyClass {
    public static void main(String args[]) throws Exception {
        String param1 = "value1";
        String param2 = "value2";
        String param3 = "value3";
    
        String encodedParam1 = URLEncoder.encode(param1, "UTF-8");
        String encodedParam2 = URLEncoder.encode(param2, "UTF-8");
        String encodedParam3 = URLEncoder.encode(param3, "UTF-8");
    
        String url = "https://www.commentsinfo.com/search?" +
                    "param1=" + encodedParam1 +
                    "&param2=" + encodedParam2 +
                    "&param3=" + encodedParam3;

        System.out.println(url);
    }
}
   
   
   
   
/*
run:
    
https://www.commentsinfo.com/search?param1=value1&param2=value2&param3=value3
    
*/

 



answered Nov 20, 2023 by avibootz

Related questions

3 answers 232 views
1 answer 113 views
3 answers 246 views
1 answer 166 views
1 answer 154 views
154 views asked Aug 7, 2020 by avibootz
1 answer 230 views
...