开发者

Is there a way to encode a URL in velocity template

Excuse my ignorance but I am new to Velocity and trying to fix someone else's problem. I need to encode a URL insid开发者_开发百科e the velocity template. I create a url and as part of the query string I pass in a page name a user created. This page can contain special characters like ëðû. The url would look like http://foo.com/page1/jz?page=SpecialChars_ëðû


To encode URL inside a template you can use:

$esc.url($myUrl)

which is a part of EscapeTool.

Note: This required to use velocity tools jar, in addition to the velocity jar. (It will not throw exception if you will not have it). Moreover, you might want to check you configuration, as describes here


I know it is late. Here is how I solved this today. In the class calling the engine, you could say

configure("esc",new EscapeTool());
context.put("url", "http://www.google.com");

Now in the template you could say

$esc.url($url)


I was just not willing to use the EscapeTool in velocity for an url-encoding. Hence, here's the solution i got -

you can use $httpUtil.decodeURL($siteURL) / $httpUtil.encodeURL($siteURL) for URL Encoding in Velocity

Also ,you can use $htmlUtil.escapeAttribute() for escaping text/html Content in Velocity.

$htmlUtil.escapeAttribute($refSiteName)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜