Sunday, September 10, 2017

JSP: escape XML


In JSP:

<%@ taglib uri = "http://java.sun.com/jsp/jstl/functions" prefix="fn" %>

<% String str = "<abc &  ' \">"; %>

<html>
<body>

<p>Escaped string: <%= fn:escapeXml(str) %> </p>

</body>
</html>
 

This requires the JSTL 1.2 JAR, which can be downloaded at https://mvnrepository.com/artifact/javax.servlet/jstl/1.2



No comments:

 
Get This <