JSTL转义特殊字符 [英] JSTL escaping special characters
问题描述
在JSP中,我使用字段名作为id,名称可以是任何类似的东西,如
id =& (OR)
id =aaa& amp; bbb
我没有任何其他选项可以使用除名字之外的ID,这是我从后端获得的唯一的东西。
所以,是否有任何逻辑删除使用JSTL的所有特殊字符。
在目前的情况下,在JS中,我将使用ID进行一些操作。
请建议,提前感谢...
JSTL提供了两种转义HTML特殊字符的方法:
<%@ taglib prefix =curi =http://java.sun.com/jsp/jstl/core%>
...
< c:out value =$ {myName}/>
和
$ {fn:escapeXml(myName)}
都将特殊字符转换为各自的HTML实体:(
& lt;
,&
成为& amp;
...)。
请注意,ID必须编码HTML,但不在JavaScript中。
I have this weird issue with special characters. In JSP, I am using field name as id and the name can be anything like
id="&lt;1 and &>2" (OR)
id="aaa & bbb"
I don't have any other option to use ID's other than names, that what the only thing I get from backend.
So, Is there any logic to remove all the special characters using JSTL. With the present scenario, In JS I will do some operations with the ID. this is causing many issues for each kind of browser.
Please suggest, Thanks in advance...
The JSTL provides two means of escaping HTML special chars :
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
...
<c:out value="${myName}"/>
and
${fn:escapeXml(myName)}
Both wil transform the special chars into their respective HTML entities : (<
becomes <
, &
become &
...).
Note that the IDs must be encoded in HTML, but not in JavaScript.
这篇关于JSTL转义特殊字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!