Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

display html via JSTL in Spring MVC

I have something like

model.addAttribute("msg", "<b>akhil</b>");
return "index";

in my Controller.

In my view page I wrote

<body>
    <h2>Hello World!</h2>
    <c:out value="${msg}" />
</body>

But the output is &lt;b>akhil&lt;/b> as against <b>akhil</b>. Why is it so and what should be done to get <b>akhil</b>.

like image 648
Akhil K Nambiar Avatar asked Jan 25 '12 12:01

Akhil K Nambiar


People also ask

Can we use JSTL in HTML?

No. It is not possible to have JSTL in HTML page.

Is JSTL used in spring?

JavaServer Pages Tag Library (JSTL) is a set of tags that can be used for implementing some common operations such as looping, conditional formatting, and others. Here we will be discussing how to use the Maven build tool to add JSTL support to a Spring MVC application.

Which tag is used in JSTL to show the output?

The <c:out> tag is similar to JSP expression tag, but it can only be used with expression. It will display the result of an expression, similar to the way < %=... % > work.


1 Answers

This is because <c:out> uses XML escaping for the characters '<' and >.

Set the option escapeXml=false of c:out to output your text in bold letters:

<c:out value="${msg}" escapeXml="false"/>
like image 160
stacker Avatar answered Oct 11 '22 13:10

stacker