user1738638
user1738638

Reputation: 53

how to display a text with tags in jsp

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

Answers (4)

Chamdarig Dall
Chamdarig Dall

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

BalusC
BalusC

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

Shashank Kadne
Shashank Kadne

Reputation: 8101

You have to escape these characters..

welcome&lt;to&gt;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

Anirudh Ramanathan
Anirudh Ramanathan

Reputation: 46778

"welcome&lt;to&gt;Jsp"


&gt; (greater than) - (>)
&lt; (less than)    - (<)

These characters need to be encoded this way to actually display them.

Upvotes: 1

Related Questions