我有一组可用的值,但不幸的是,一些变量名称包含一个空格。我不知道如何在页面中简单地输出这些。我知道我没有很好地解释这一点(我是 JSP 设计者,而不是 Java 编码者)所以希望这个例子能说明我正在尝试做的事情:
<c:out value="${x}"/>
输出到页面(人工包装)为:
{width=96.0, orderedheight=160.0, instructions=TEST ONLY. This is a test.,
productId=10132, publication type=ns, name=John}
我可以使用输出名字
<c:out value="${x.name}"/>
没问题。问题是当我尝试获取“发布类型”时...因为它有一个空格,我似乎无法获取 <c:out>
显示它。
我试过:
<!-- error parsing custom action attribute: -->
<c:out value="${x.publication type}"/>
<!-- error occurred while evaluating custom action attribute: -->
<c:out value="${x.publication+type}"/>
<!-- error occurred while parsing custom action attribute: -->
<c:out value="${x.'publication type'}"/>
<!-- error occurred while parsing custom action attribute: -->
<c:out value="${x.publication%20type}"/>
我知道真正的解决方案是正确设置变量名称的格式(即:没有空格),但我有一段时间无法更新代码。这可以做到吗?非常感谢任何帮助。
最佳答案
你试过吗:
<c:out value="${x['publication type']}"/>
我假设 Map
是其背后的 Java 类型。
关于java - JSTL <c :out> where the element name contains a space character,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/661008/