Java JSTL <c:out> 其中元素名称包含空格字符
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/661008/
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
JSTL <c:out> where the element name contains a space character
提问by
I have an array of values being made available, but unfortunately some of the variable names include a space. I cannot work out how to simply output these in the page. I know I'm not explaining this well (I'm the JSP designer, not the Java coder) so hopefully this example will illustrate what I'm trying to do:
我有一组可用的值,但不幸的是,一些变量名称包含一个空格。我无法弄清楚如何在页面中简单地输出这些。我知道我没有很好地解释这一点(我是 JSP 设计师,而不是 Java 编码员)所以希望这个例子能说明我正在尝试做的事情:
<c:out value="${x}"/>
outputs to the page (artificially wrapped) as:
输出到页面(人工包装)为:
{width=96.0, orderedheight=160.0, instructions=TEST ONLY. This is a test.,
productId=10132, publication type=ns, name=John}
I can output the name by using
我可以使用输出名称
<c:out value="${x.name}"/>
no problems. The issue is when I try to get the "publication type"... because it has a space, I can't seem to get <c:out>
to display it.
没问题。问题是当我尝试获取“出版物类型”时……因为它有空格,我似乎<c:out>
无法显示它。
I have tried:
我试过了:
<!-- 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}"/>
I know the real solution is to get the variable names formatted correctly (ie: without spaces) but I can't get the code updated for quite a while. Can this be done? Any help greatly appreciated.
我知道真正的解决方案是正确格式化变量名(即:没有空格),但我很长一段时间都无法更新代码。这能做到吗?非常感谢任何帮助。
采纳答案by Eddie
Have you tried:
你有没有尝试过:
<c:out value="${x['publication type']}"/>
I am assuming that a Map
is the Java type behind this.
我假设 aMap
是这背后的 Java 类型。