2013-02-17 46 views
1

我想建立链接到src属性取决于一些参数删除新的生产线,由JSTL标签产生

<%@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标签所产生的空间和新线路?

回答

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