Search code examples
javaalfrescoalfresco-webscripts

How can I wrap parameter value in URL to include parameter separator


I am working on project in alfresco, and need to send a value as a keyword to do the search. Now, my question is, can I wrap that value somehow to include & separator also? My URL looks like:

https://myproject/share/proxy/alfresco/slingshot/search?term=belux&50&qw

The value that I am sending as a parameter is: belux&50&qw

The problem is when I done the search, search engine get confused and read that parameter as belux only. Probably search engine looks on that & as on separator an as soon as he finds it he stops, that is, reads the value to the first character only. In my case, he reads only belux.

Is it posible to read the whole value, including the & sight?

Thanks,


Solution

  • URLEncoder is the solution. You just need to remember to encode only the name and/or value of the individual query string parameter, not the whole URL, and certainly not the query string parameter separator character & or the parameter name-value separator character =. Example :

    String url = "https://example.com?q=" + URLEncoder.encode("belux&50&qw", StandardCharsets.UTF_8);