2013-01-24 75 views
1

我在窗體上使用了1個搜索選項。在這裏,當我通過任何特殊 字符如& or $它不會在搜索框中保存該請求參數是,但它正在處理我的搜索請求。查詢參數中的特殊字符

+0

編碼這個值 –

回答

2

您需要URL encode查詢字符串中的值。

+0

如何,我可以在我的春天控制器使用它呢? – Amruta

+0

我已經在我的jsp中使用<%@ page language =「java」errorPage =「/ error.jsp」pageEncoding =「UTF-8」contentType =「text/html; charset = utf-8」%>在我的控制器中使用URLEncode不會是2次編碼我的查詢參數 – Amruta

0

我不知道Java,但在通過Google URL參數向谷歌翻譯發送用戶文本時,我使用了類似於下面的代碼。 (已分配的假設會將myText,myURL和myTextURL值。)

<script> 
function transfix(isURL,form) { 
    if(isURL) window.open(myURL  + encodeURIComponent(myText)); 
    else  window.open(myTextURL + decodeURIComponent(myText)); 
} 
</script> 

<form target=_blank id="translate" name="translate"> 

<input type="button" value="Text" onclick="transfix(false,this.form)"> 
<input type="button" value="URL" onclick="transfix(true,this.form)"> 

</form>