Html 如何在JSP中的两个变量之间插入空格?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13367921/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to insert a space between two variables in JSP?
提问by zw324
I have one line of html in a form on a JSP page like this:
我在 JSP 页面上的表单中有一行 html,如下所示:
<c:forEach var="entry" items="${set}">
<input type="checkbox" name="thing" value="${entry.key} ${entry.value}">
</c:forEach>
However, the space between the key and the value ${entry.key} ${entry.value}
is lost when the form is submitted. I've tried using a \
before the , in that case both the
\
and the are still there when submitting.
但是,${entry.key} ${entry.value}
提交表单时,键和值之间的空格会丢失。我试过在\
之前使用 a ,在这种情况下,提交时the
\
和 the仍然存在。
It seems that Java EL does not preserve isolated spaces, is that right? If so, is there a valid workaround?
Java EL 似乎不保留隔离空间,对吗?如果是这样,是否有有效的解决方法?
EDIT: This is so silly of me, many thanks to Cthulhu. But I still don't understand the behavior after adding a \
. Why would that cause the space to show?
编辑:这对我来说太愚蠢了,非常感谢克苏鲁。但是我仍然不明白添加\
. 为什么这会导致空间显示?
回答by Anirudh Ramanathan
回答by wessel
${entry.key}${' '}${entry.value}
was my way to fix this. Seems a little less verbose than the
是我解决这个问题的方法。似乎没有那么冗长
<c:out value="${bean.foo} ${bean.bar} ${bean.waa}" />
from the other thread.
从另一个线程。