url encoding of java string in freemarker template file

Posted by Wai on
URL: http://ofbiz.116.s1.nabble.com/url-encoding-of-java-string-in-freemarker-template-file-tp4708874.html

In a freemarker template, I have the following. Of course, it can also come from a java method.
<#assign test=Static["java.lang.String"].format("http://example.com/page?a=1&b=2") >
<p>result1=${test}</p>
<p>result2=${test?url('utf-8')}</p>

The output to the webbrowser shows...
result1=http://example.com/page?a=1&b=2
result2=http%26%23x3a%3B%26%23x2f%3B%26%23x2f%3Bexample.com%26%23x2f%3Bpage%26%23x3f%3Ba%26%23x3d%3B1%26amp%3Bb%26%23x3d%3B2

I'm interesting in the following correct output...
result1=http://example.com/page?a=1&b=2
result2=http%3A%2F%2Fexample.com%2Fpage%3Fa%3D1%26b%3D2


Could someone tell me what is the problem and how to solve it.
Thanks in advance.