2012-04-25 60 views
4

我在與Oracle DB Java EE應用程序的工作。 現在網頁上的某些內容有一些特殊的字符,我需要逃避它們。 的字符來作爲顯示如下:需要特殊字符轉義在Java Web應用程序

€˜T’ ! “One Chase.†$ % & () '/: ? ` â€」 â€「 _ ‚ " Test 

是任何人都知道這個編碼是什麼樣的性格和我怎能逃脫呢?我需要逃避他們,並用空白取代他們。

回答

0

可以模式匹配字符串,要麼建立的無效字符黑名單或具有有效字符白名單....像下面

Pattern p = Pattern.compile(blackList); // or reverse with a white list 
Matcher m = p.matcher(unsafeInputString); 
if (m.matches()) 
{ 
    // Invalid input: reject it, or remove/change the offending characters. 
} 
else 
{ 
    // Valid input. 
} 
+0

這些是unicode字符... http://en.wikipedia.org/wiki/List_of_Unicode_characters – 2012-04-25 14:25:06

1

這些字符的副作用代碼不能正確處理編碼(什麼是假設UTF-8是ISO-8859-1,反之亦然) - 他們是目前垃圾。您需要修復您的應用以正確呈現它們。沒有必要用空白替換它們或做任何過濾。

閱讀這篇文章,然後http://www.joelonsoftware.com/articles/Unicode.html檢查數據庫的交互,和你的JSP應用服務器設置。