I'm having an issue with the URL encoding of a search query, I have this in a Velocity template.
<form method="GET" action="$req.contextPath/plugins/peopledirectory/search.action">
<div class="greyboxfill" style="width: 420px">
<input type="hidden" name="pageId" value="$pageId"/>
<input type="text" name="search" id="search" size="30" value="$search"/>
<input type="submit" name="searchbtn" value="Pesquisar">
</div>
</form>
The problem is that when I click the submit button, the search string is not URL encoded and if I search for something like ME&A, it only searches for ME. Is there any definition needed in Velocity to make that work?
I seen around the web that the form HTML tag has a inner URL encoding, why is it not working in this 开发者_开发技巧case?
The best thing to do is explicitly escape the string using EscapeTool from VelocityTools. This is an additional library that you'll need to download and then include in your velocity context.
URL encoding is then as easy as:
$escape.url($search)
精彩评论