How to insert a space between two variables in JSP?

I have one line of html in the form on a JSP page, for example:

<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 of ${entry.key} ${entry.value} is lost when the form is ${entry.key} ${entry.value} . I tried using \ before , in this case, everything \ and still present when shipping.

Java EL doesn't seem to preserve isolated spaces, right? If so, is there a valid workaround?

EDIT: This is so stupid that I am very grateful to Cthulhu. But I still don't understand the behavior after adding \ . Why should this show space?

+4
source share
2 answers

You can insert spaces using: &nbsp;

Character Object References

Change This seems to be a mistake in how spaces are handled by the EL parser, so you should use either html objects like &nbsp; , or other methods indicated here .

+8
source
 ${entry.key}${' '}${entry.value} 

was my way to fix it. Seems a little less verbose than

 <c:out value="${bean.foo} ${bean.bar} ${bean.waa}" /> 

from another thread.

+3
source

Source: https://habr.com/ru/post/1445855/


All Articles