LancerX
LancerX

Reputation: 1231

Remove new lines, generated by JSTL tags

I want to build link to src attribute which depends on some parameters

<%@page trimDirectiveWhitespaces="true" %>
...
<iframe style="border: 0; width: 100%; height: 100%;"
    src="http://localhost:8080/AppName?
<c:if test="${not empty it.paramOne}">
    paramOne=${it.paramOne}
</c:if>
<c:if test="${not empty it.paramTwo}">
    &paramTwo=${it.paramTwo}
</c:if>
<c:if test="${not empty it.paramThree}">
    &paramThree=${it.paramThree}
</c:if>
">
Your browser doesn't support iFrames. </iframe>

The code above, generates the following html

<iframe style="border: 0; width: 100%; height: 100%;" src="http://localhost:8080/AppName?

paramOne=val1
&amp;paramTwo=val2
&amp;paramThree=val3
">
    Your browser doesn't support iFrames. </iframe>

The link looks

http://localhost:8080/AppName/?%20%20%20%20%20%20paramOne=val1%20%20%20&paramTwo=val2%20%20%20&paramThree=val3

But I want to get

http://localhost:8080/AppName/?paramOne=val1&paramTwo=val2&paramThree=val3

I found this http://flgor.blogspot.com/2011/07/jsp-new-line.html but it is not what I want, I think.

So how can I get rid of the spaces and new lines which are generated by JSTL tags?

Upvotes: 1

Views: 574

Answers (1)

stan
stan

Reputation: 4995

Try putting that all in one line:

<c:set var="url" value="http://localhost:8080/AppName?"/>

<c:if test="${not empty it.paramOne}">
    <c:set var="url" value="${url}paramOne=${it.paramOne}"
</c:if>
<c:if test="${not empty it.paramTwo}">
    <c:set var="url" value="${url}&paramTwo=${it.paramTwo}"
</c:if>
<c:if test="${not empty it.paramThree}">
    <c:set var="url" value="${url}&paramThree=${it.paramThree}"
</c:if>

<iframe style="border: 0; width: 100%; height: 100%;"
    src="${url}">

Upvotes: 2

Related Questions