Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

when tag in foreach inserts space character to rendered page

665045Nov 17 2010 — edited Nov 18 2010
Hi,

It seem like a small issue, but it really messes up my webpage when doing something like this:

The following JSP page:

<%@ taglib uri='http://java.sun.com/jsp/jstl/core' prefix='c'%>
<html>
<body>
<%
String[] sA = {"a","b","c","d"};
pageContext.setAttribute("sA", sA);
%>
<c:forEach var="s" items="${sA}" varStatus="status">
<c:choose>
<c:when test="${s == 'a'}">
<c:out value="${sA[0]}"/>
</c:when>
<c:when test="${s == 'b'}">
<c:out value="${sA[1]}"/>
</c:when>
<c:when test="${s == 'c'}">
<c:out value="${sA[2]}"/>
</c:when>
<c:when test="${s == 'd'}">
<c:out value="${sA[3]}"/>
</c:when>
</c:choose>
</c:forEach>
</body>
</html>

renders this to my browser:
a b c d
So it puts spaces between each chars

But when I put all the codes from forEach to /forEach, it renders without additional spaces:
<c:forEach var="s" items="${sA}" varStatus="status"> .... all the c:choose and stuff goes here ... </c:forEach>
abcd


Can I force the renderer somehow to not to put spaces? I know that putting everything into one line solves my problem, but I don't want to do that, no one can ever read or modify that jsp again. My actual jsp has about 50 c:when tags, it would be quite a disgusting ugly code formatting and jsp page at the end...


Thanks for the help!
Kumite
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 16 2010
Added on Nov 17 2010
2 comments
896 views