删除由JSTL标记生成的新行

时间:2013-02-17 22:21:08

标签: java jsp jstl newline

我想构建依赖于某些参数的src属性的链接

<%@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>

上面的代码生成以下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>

链接看起来

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

但我想得到

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

我发现这个http://flgor.blogspot.com/2011/07/jsp-new-line.html,但我认为这不是我想要的。

那么如何摆脱JSTL标签生成的空格和换行?

1 个答案:

答案 0 :(得分:2)

尝试将所有内容放在一行中:

<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}">