[英]Escaping HTML special character with JSP or JQuery
My JSP file contains a table with the following row: 我的JSP文件包含具有以下行的表:
<td class="description" id="${doc.id}"></td>
I want it to be empty at first, as above. 我希望它一开始是空的,如上所述。 Later, after the page is loaded and some logic is processed, I want to fill it asynchronously with a content using JQuery
.html
method: 稍后,在加载页面并处理了一些逻辑之后,我想使用JQuery
.html
方法用内容异步填充它:
$("#${doc.id}").html("${doc.description}");
For regular user inputs everything works fine, but error occurs, when a user enters special character: "
对于普通用户输入的一切工作正常,但是会出现误差,当用户输入特殊字符:
"
How can I prevent application from reading that character as special, and have the application running correctly? 如何防止应用程序将该字符读为特殊字符,并使应用程序正确运行?
I have tried to use JSP escape functions like this: 我试图使用像这样的JSP转义功能:
$("#${doc.id}").html("${fn:escapeXml(doc.description)}");
And this: 和这个:
$("#${doc.id}").html("<c:out value="${doc.description}"/>");
And neither first nor second worked. 第一和第二都没有。 Why?
为什么?
Here is one way - seeing you already have the data on the page 这是一种方法-看到页面上已经有数据
<td class="description hide" id="${doc.id}"><c:out value="${doc.description}"/></td>
where 哪里
.hide is {display:none} .hide是{display:none}
and then 接着
$("#${doc.id}").show();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.