gpt4 book ai didi

Java - Scriptlet 到类的转换

转载 作者:行者123 更新时间:2023-12-01 14:36:23 25 4
gpt4 key购买 nike

我正在尝试获取项目中的任何 jsp scriptlet 并将它们转换为模型类。因为我们都知道 jsp 中的 scriptlet 是邪恶的。但当我尝试将其分离到一个类中时,这一段代码确实给我带来了问题。这是一段相当简单的循环子节点的代码。这是我的 jsp,它运行得很好:

<%
NodeIterator ni = currentNode.getNodes();

while (ni.hasNext()) {
Node nii = ni.nextNode();
String printNodeTitle = nii.getProperty("fileReference").getString();
%>
<img src="<%= printNodeTitle %>" />
<%
}
%>

这是我的模型类中的代码:

public class fileReference(){

Node currentNode = (Node) context.getAttribute("currentNode");
NodeIterator ni = currentNode.getNodes();

while (ni.hasNext()) {
Node nii = nodeLoop.nextNode();
String printNodeTitle = nii.getProperty("fileReference").getString();
}

public String getPrintNodeTitle() { return printNodeTitle; }
}

奇怪的是我没有收到错误,只是没有得到任何输出。有任何想法吗?非常感谢任何帮助。

最佳答案

你的变量 ni 应该是可迭代的,所以 while 循环应该如下所示:

while (ni.hasNext()) {

我不知道你从哪里获取nodeLoop变量...可能它只是一个空列表迭代器?

关于Java - Scriptlet 到类的转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16453364/

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