-1

I have a small problem in extracting the values of the GET hyperlink. for example:
It has to accept the input from user
INPUT: https://www.something.comsignin/service?username=test&pwd=test&profile=developer&role=ELITE&key=manager

  • **

  • OUTPUT

** In the above hyperlink i want values of ,
USERNAME:test
PWD:test
PROFILE::developer
..... This has to be the output.

Please help me with a code in JAVA. Thanks in advance.

Mr.Robot
  • 489
  • 2
  • 8
  • 17
  • Maybe [here is the answer](http://stackoverflow.com/questions/4128436/query-string-manipulation-in-java). – Wiktor Stribiżew Jun 26 '15 at 13:44
  • Some simple string operations would probably do the trick since the patter for a query string in an url would be `url?p1=v1&p2=v2...`. Just split at the appropriate characters. – Thomas Jun 26 '15 at 13:46

1 Answers1

2

First transform your String to URL and then using getQuery() method you can get only paramateres e.g username=abc&password=def... of URL and then u can split it using '&'

    String query = "https://www.something.comsignin/service?username=test&pwd=test&profile=developer&role=ELITE&key=manager";
    URL u = new URL(query);
    String param = u.getQuery();
    String paramSplit[] = param.split("&");
    System.out.println(paramSplit[0] + "\n" + paramSplit[1]); //only username and password
    for (String s : paramSplit)
        System.out.println(s); 

Output:

username=test
pwd=test
profile=developer
role=ELITE
key=manager
Hiren
  • 1,427
  • 1
  • 18
  • 35
  • But,I want only the values of username,pwd so that i could use those value anywhere? thanks in advance.. @Hiru – Mr.Robot Jun 26 '15 at 14:13
  • Yes, can i store the values of username ,password,profile,role,key in any variables so that i can display the output like.
    Un : test pw : test prfl : developer rol : ELITE key : manager.. Your answers are perfect i just want to know in depth .. Thanks in advance
    – Mr.Robot Jun 26 '15 at 14:22
  • you can again split with "=" this will produce test,test,developer,ELITE,manager – Hiren Jun 26 '15 at 14:23
  • Please tell me in detail .Don't mind im a beginner.@Hiru – Mr.Robot Jun 26 '15 at 14:28
  • have a look here http://stackoverflow.com/questions/13437768/adding-strings-to-an-arraylist – Hiren Jun 26 '15 at 14:30
  • Im expecting your code ...@Hiru – Mr.Robot Jun 26 '15 at 14:45