SJS
SJS

Reputation: 5667

How can I make Spring-MVC output HTML

How can I make Spring-MVC output HTML. Right now I have Spring-MVC filling in data in a List like the one below:

 <ul>
     <li><c:out value="${memberrequest.name}"/></li>
     <li><c:out value="${memberrequest.title}"/></li>
     <li>District: <c:out value="${memberrequest.district}"/></li>
     <li><c:out value="${memberrequest.school}"/></li>
     <li><c:out value="${memberrequest.requestor}"/></li>
 </ul>

the out put looks like:

enter image description here

But if the data is blank like title, school etc I don't want a line to blank so I was thinking that I could creating this list in the spring code and then pass the html back to the JSP page but it looks like Spring will not let you do it

Upvotes: 0

Views: 811

Answers (2)

Tom Wadley
Tom Wadley

Reputation: 121863

If you really want to do this you can use the escapeXml="false" attribute on c:out like so:

<c:out value="${myHtmlString}" escapeXml="false"/>

But as parsifal says, it's best to construct your HTML in your view if you can.

Upvotes: 0

parsifal
parsifal

Reputation: 206

Returning HTML from your controller defeats the very idea of MVC, because your controller takes over the responsibility of the view.

Instead, use the <c:if> tag within your JSP. More information here: http://docs.oracle.com/javaee/1.4/tutorial/doc/JSTL4.html#wp74001 (note: the first paragraph of this explanation seems to indicate that you should use a scriptlet; it really doesn't, and if you read down you'll see the JSTL approach).

Upvotes: 2

Related Questions