Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
从 jsp 变量中消除单引号和双引号的最佳方法是什么?
认为text="hsdhakb'asda"'ass'as'd"
text="hsdhakb'asda"'ass'as'd"
我们有两个选择 ,要么使用fn:replace要么fn:escapeXml()
fn:replace
fn:escapeXml()
<c:set var='text' value='${text}'/>
你应该使用fn:escapeXml()因为它转义了引号和其他可以被解释为 XML 标记的字符。.
它还有助于防止 JSP 中的 XSS 攻击。
您可以查看StringEscapeUtils