开发者

JSP c:set to value returned by x:out displays special characters code

I have an xml document. When parsing that doc I want to do

<c:set var="fullName">
<x:out select="$character/fstName"/>.<x:out select="$character/famName"/>
</c:set>

and then later

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

This displays special characters html code instead of the character itself (ie. apostrophe becomes &#38#039)

I have read a similar issue on that page "how-can-i-escape-special-html-characters-in-jsp" but this seems to be a solution for c:out only. I tried it in my case a开发者_如何学Gond it does not seem to work for x:out

thanks in advance


By default, <x:out> will convert certain characters to their associated entity codes. If you don't want that to happen, try something like:

<x:out select="$character/fstName" escapeXml="false"/>


So this is the final solution:

<c:set var="fullName">
<x:out select="$character/fstName" escapeXml="false"/>.<x:out select="$character/famName" escapeXml="false"/>
</c:set>

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

I guess escapeXml="false" is something to be used all the time if you nest your x:out in a c:set unless the expected nodes' content has numbers only.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜