Reputation: 53
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.
Upvotes: 5
Views: 7027
Reputation: 1
I just added spaces :)
<body bgcolor="#333" text="#fff">
<!-- jsp expression -->
<p>Expression < % = new java.util.Date() % ></p>
<p> <%= new java.util.Date() %></p>
<!-- jsp Scriptlet -->
<p>Scriptlet < % Java code 1 to many lines % ></p>
<!-- jsp Declaration -->
<p>Declaration < % ! variable or method declaration %></p>
<p>JSP comment < %-- --%></p>
Upvotes: 0
Reputation: 1109432
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?
Upvotes: 1
Reputation: 8101
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")
Upvotes: 2
Reputation: 46778
"welcome<to>Jsp"
> (greater than) - (>)
< (less than) - (<)
These characters need to be encoded this way to actually display them.
Upvotes: 1