问题
I want to display a text called
"welcome<to>Jsp"
In page source also i'm seeing as "welcomeJsp"
But in HTML its displaying as "welcomeJsp" alone. Please guide me.
回答1:
You have to escape these characters..
welcome<to>Jsp
I would advice using Apache's StringEscapeUtils class(available in org.apache.commons.lang ) function escapeHtml()
for escaping HTML.
StringEscapeUtils.escapeHtml("welcome<to>Jsp")
回答2:
"welcome<to>Jsp"
> (greater than) - (>)
< (less than) - (<)
These characters need to be encoded this way to actually display them.
回答3:
Use JSTL <c:out> tag or fn:escapeXml() function.
<c:out value="welcome<to>Jsp" />
or
${fn:escapeXml('welcome<to>Jsp')}
You can even use it on model values.
<c:out value="${bean.property}" />
or
${fn:escapeXml(bean.property)}
Those two should by the way always be used when it concerns user-controlled input, you're otherwise totally open to XSS attack holes. See also our JSP wiki page and What is the general concept behind XSS?
来源:https://stackoverflow.com/questions/13303128/how-to-display-a-text-with-tags-in-jsp