gpt4 book ai didi

java - 在 JSP 中,是否可以打印名称在另一个变量中的变量的值?

转载 作者:行者123 更新时间:2023-11-30 09:58:00 25 4
gpt4 key购买 nike

我遇到的问题是这样的有变数

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com