Re: 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-tp4708874p4708920.html
The issue was the actual _result2_ is longer then the desired _result2_. Notice that the actual _result2_ contain many more bytes then the desired. I think the issue is that a java string is using unicode/utf16. That's why there are so many more bytes.
A solution I used was to create a StringWrapper for the _test_ variable and then use the freemarker ?url method. eg...
<#assign test=Static["java.lang.String"].format("
http://example.com/page?a=1&b=2") >
<#assign test=StringUtil.wrapString(test)>
<p>result1=${test}</p>
<p>result2=${test?url('utf-8')}</p>
Resulting output to the browser is...
result1=
http://example.com/page?a=1&b=2result2=http%3A%2F%2Fexample.com%2Fpage%3Fa%3D1%26b%3D2