Wednesday, November 19, 2025
HomeLanguagesJavaGet Credential Information From the URL(GET Method) in Java

Get Credential Information From the URL(GET Method) in Java

Given a URL as a string, the task is to extract username, password, profile, role, and key from the URL in a GET Method.

Examples:

Input: 
http://www.neveropen.com/signin/service?username=test&pwd=test&profile=developer&role=ELITE&key=manager
Output:
username: test
pwd: test
profile: developer
role: ELITE
key: manager

Input: http://www.neveropen.com/signin/serviceusername=Vikas&pwd=1@@2&profile=developer&role=SoftwareDeveloper&key=Assistant

Output:
username: Vikas
pwd: 1@@2
profile: developer
role: SoftwareDeveloper
key: Assistant

Approach: 

  • Firstly, Remove the web Link from the given URL using the split method.
  • Secondly, Split the URL where “&” operator is Found.
  • In the end, Replace each index value from “=” to “: “.

Below is the implementation of the above approach:

Java




// Java Program to Get Credential
// Information From the URL(GET Method)
import java.util.*;
import java.io.*;
public class ExchangeCharacter {
 
    public static void main(String args[]) throws Exception
    {
 
        BufferedReader scan = new BufferedReader(
            new InputStreamReader(System.in));
       
          // taking url as a string
        String url
        String str[] = url.split("\\?");
        String arr[] = str[1].split("&");
        for (String s : arr) {
            System.out.println(s.replace("=", ": "));
        }
    }
}


Output:
 

username: Vikas
pwd: 1@@2
profile: developer
role: SoftwareDeveloper
key: Assistant
RELATED ARTICLES

Most Popular

Dominic
32404 POSTS0 COMMENTS
Milvus
97 POSTS0 COMMENTS
Nango Kala
6775 POSTS0 COMMENTS
Nicole Veronica
11924 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11994 POSTS0 COMMENTS
Shaida Kate Naidoo
6903 POSTS0 COMMENTS
Ted Musemwa
7159 POSTS0 COMMENTS
Thapelo Manthata
6859 POSTS0 COMMENTS
Umr Jansen
6846 POSTS0 COMMENTS