user3310291
user3310291

Reputation:

<c:set var="s" value="class=\"selected\"" scope="request"/> sets unexpected String in jstl

I have some links in my JSP page and I want to make the selected link Bold. I have CSS as :

.selected { font-weight: bold; }

and my JSP Code is :

<li <c:choose>
    <c:when test="${subject.subjectId == param.subj_id}">
    <c:set var="s" value="class=\"selected\"" scope="request"/> <!-- Here I'm setting class=selected
    <c:out value="${s}"/>
    </c:when>
</c:choose>><a href='/super-context/view-controller?action=view-content&subj_id=
    <c:out value="${subject.subjectId}"/>'>
    <c:out value="${subject.subjectName}" />
    </a></li>

But above code does not work and when I go to page-source I see the line below

<c:out value="${s}"/>

prints :

<li class=&#034;selected&#034;>

please tell how to get this in :

<li class="selected">

Upvotes: 0

Views: 548

Answers (2)

Braj
Braj

Reputation: 46851

By default, escapeXml is true, and the <c:out> tag thus escapes the HTML If you don't want to escape, you could simply use

${s}

instead of

<c:out value="${s}"/>

There is no need of <c:out> at all in your case. Do it in the same way for all the <c:out> tag.


c:out escapes HTML characters so that you can avoid cross-site scripting.

For more info have a look at below posts:

Upvotes: 2

Thilo
Thilo

Reputation: 262644

<c:out> escapes special characters such as quotes.

If you don't want that, you can turn it off:

<c:out value="class=\"selected\"" escapeXml="false"/>

Upvotes: 1

Related Questions