I need to display following special characters in a table TD (exclude the back slash in between < symbol and forward slash),
1) \'/<\\/@/tes
Everthing which get sent by JSP is by default treated as HTML by the webbrowser. The <
indicates start of a HTML tag and thus the webbrowser will parse it as such (and eventually fail due to a syntax error).
You want to escape those HTML special characters like <
, >
, &
and "
.
< will be displayed as <
> will be displayed as >
& will be displayed as &
" will be displayed as "
If it is dynamic text, this is best to be done with JSTL <c:out> tag.
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
...
<c:out value="${bean.text}" />
Of if you want to set a HTML attribute, the JSTL fn:escapeXml() function is nicer.
<%@taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
...
<input type="text" value="${fn:escapeXml(bean.text)}" />
I got it to work on JSP by adding this directive to the page
<%@ page contentType="text/html; charset=UTF-8" %>