How to insert a space between two variables in JSP

2019-06-26 03:00发布

This question already has an answer here:

I have one line of html in a form on a JSP page like this:

<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.

It seems that Java EL does not preserve isolated spaces, is that right? If so, is there a valid workaround?

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?

标签: html forms jsp el
2条回答
Animai°情兽
2楼-- · 2019-06-26 03:05

You can insert white-spaces using: &nbsp;

Character Entity References

Edit: Seems to be a bug in the way spaces are handled by the EL parser, so you should use either html entities like &nbsp; or the other ways outlined here.

查看更多
我命由我不由天
3楼-- · 2019-06-26 03:05
${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.

查看更多
登录 后发表回答