我遇到的问题是这样的 有变数
<core:set var="type">*one of: load,migrate, or ...* </core:set>
load, migrate, 的值是一张 map 。现在,我想根据类型打印这些值?有可能吗?
最佳答案
这将达到与@Chii 的回答相同的效果:
<c:set var="attributeName" value="foo"/>
<%
out.println(pageContext.getAttribute(attributeName) + " = " + pageContext.getAttribute(pageContext.getAttribute(attributeName)));
%>
尽管很讨厌,但如果您需要的话,它会列出页面范围中的所有属性:
<%
for (String attributeName : pageContext.getAttributeNamesInScope(PageContext.PAGE_SCOPE))
{
out.println(attributeName + " = " + pageContext.getAttribute(attributeName));
}
%>
不要认为在 JSTL 中有办法做到这一点,但您通常只在调试期间需要它,所以我对 scriptlet 代码没有这样的问题。
关于java - 在 JSP 中,是否可以打印名称在另一个变量中的变量的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1311260/