我有一個Java HashMap<String,String>
,它通過Spring的ModelAndView
提供給JSP頁面(itemTypesByKey
),並且包含一個包含鍵列表的單獨結構。 (這些鍵可能導致或不導致有效的查找。)我枚舉這些鍵,並從地圖中獲取值。使用包含單引號的字符串鍵的EL映射查找
Map<String, String> itemTypes = new HashMap<>();
itemTypes.put("NormalValue", "INGREDIENT");
itemTypes.put("Apostro'Value", "INGREDIENT");
ModelAndView mav = ...
mav.addObject("itemTypesByKey", itemTypes);
問題我看到的是,如果我的鑰匙包含撇號,查找失敗。
我的代碼(用於調試目的):
Key Name: ${currentKeyName}
Not Empty: ${not empty itemTypesByKey[currentKeyName]}
Type: ${itemTypesByKey[currentKeyName]}
All Suite Types: ${itemTypesByKey}
結束了打印,支持兩個獨立的按鍵:
Key Name: NormalValue
Not Empty: true
Type: INGREDIENT
All Suite Types: {NormalValue=INGREDIENT, Apostro'Value=INGREDIENT}
Key Name: Apostro'Value
Not Empty: false
Type:
All Suite Types: {NormalValue=INGREDIENT, Apostro'Value=INGREDIENT}
時,他們用來查找一個我明白逃避撇文字值,但爲什麼如果我的密鑰包含撇號,這會失敗?無論我的密鑰的值是否包含特殊字符,如何安全地在我的映射中執行查找?我使用的是Spring 3.1.4版本(mvc,表達式等),並且這個問題不會影響包含感嘆號的關鍵字,或者其他我認爲可以測試的特殊字符。
由於APOSTROPH將轉換成thier代碼(')。與引號相同的問題=(。 – reporter
不應該在任何內容被打印到頁面之前發生內部查找? –
實際上是的,但'實際上'實際上不是一個字^^ – reporter