JSP – htmlentities() PHP like function
In PHP there is a very useful function: htmlentities().
What this function does is to replace < with <, > with > and so forth. This is very useful when editing into a page some html code stored inside a database.
I can not find something similar for JSP. If you are using Struts, there is no need for something like this, but if you are using plain JSP you may not be so fortunate.
So I approached this through brute force:
<%
content = content.replace("&", "&");
content = content.replace("<", "<");
content = content.replace(">", ">");
content = content.replace("\"", """);
content = content.replace("'", "'");
%>
But this is no elegant solution and I will try to find a better one. Do you know a better one?
