0

I wanted to know if someone can help me with getting the values from a query string.

This is the example: partygo://qr/?partyId=XXX&uid=XXX&name=XXX

I want to get the values from partyId, uid and name. I really dont know if there is any encoder or sth like that.

Thanks!

2
  • maybe this other question can help you Commented Nov 15, 2018 at 8:22
  • Maybe use a REGEX and retrieve your value with that? Commented Nov 15, 2018 at 9:03

2 Answers 2

1

Solution 1:

By decoding the parameters like below,

public void getParametersFromRequest(HttpServletRequest request, HttpServletResponse response) {
    String partyId = request.getParameter("partyId");
    String uid= request.getParameter("uid");
    String name= request.getParameter("name");
}

Solution 2:

You can achieve this using below method.

public static Map<String, String> getQueryMap(String query)  
{  
    String[] params = query.split("&");  
    Map<String, String> map = new HashMap<String, String>();  
    for (String param : params)  
    {  
        String [] p=param.split("=");
        String name = p[0];  
        if(p.length>1)  {
            String value = p[1];  
            map.put(name, value);
        }  
    }  
    return map;  
} 

So then you can use:

Map params=getQueryMap(querystring);
String partyId=(String) params.get("partyId");
String uid=(String) params.get("uid");
String name=(String) params.get("name");
Sign up to request clarification or add additional context in comments.

Comments

0

This is simple GET request so you can directly get the value of query string using the request object in doGet method

public void doGet(HttpServletRequest request, HttpServletResponse response) {

   String partyid = request.getParameter("partyId");
   //similar do others

}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.