JSTL 不打印值
我有以下代码,应该返回 0 到 n - 1 之间的 m 个数字的排序列表。我已经验证该列表已正确创建,但 JSP 没有打印任何内容。谁能帮我解决这个问题吗?这是我的动作类中的方法。
public static SortedSet<Integer> createCombo(int items, int maxNum) {
if (items > maxNum) {
System.out
.println("Cannot create a combination longer than the highest possible number.");
return null;
}
for (int i = 1; i <= items; i++) {
int newNum = 0;
boolean distinctNumber = false;
while (! distinctNumber) {
newNum = (int) Math.floor(Math.random() * maxNum);
distinctNumber = true;
if (i > 1) {
Iterator<Integer> iterator = combo.iterator();
while ((iterator.hasNext()) && (distinctNumber)) {
if (newNum == iterator.next()) {
distinctNumber = false;
}
}
}
}
combo.add(newNum);
}
printCombo();
return combo;
}
这是我的控制器类中的方法。
public String execute() {
SortedSet<Integer> combo = new TreeSet<Integer>();
try {
if ((items == 0) || (maxNum == 0)) {
return "failure";
}
combo = Combo.createCombo(items, maxNum);
if (combo != null) {
HttpSession session = (HttpSession) request.getSession();
session.setAttribute("combo", combo);
}
return "success";
} catch (Exception e) {
}
return "failure";
}
这是我的 JSP。我的浏览器中仅显示 h1 标签之间的文本。
<%@ page import="java.io.*"%>
<%@ page import="java.util.List"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<html>
<head>
<title>Lotto Results</title>
</head>
<body>
<center>
<h1>Lotto Results</h1>
</center>
<s:iterator value="combo">
<c:forEach var="iterator" items="${combo.iterator}" >
${iterator.next}
</c:forEach>
</s:iterator>
</body>
</html>
I have the following code that is supposed to return a sorted list of m numbers between 0 and n - 1. I have verified that the list is created corrected, but the JSP is not printing anything. Can anyone help me with this? This is the method in my action class.
public static SortedSet<Integer> createCombo(int items, int maxNum) {
if (items > maxNum) {
System.out
.println("Cannot create a combination longer than the highest possible number.");
return null;
}
for (int i = 1; i <= items; i++) {
int newNum = 0;
boolean distinctNumber = false;
while (! distinctNumber) {
newNum = (int) Math.floor(Math.random() * maxNum);
distinctNumber = true;
if (i > 1) {
Iterator<Integer> iterator = combo.iterator();
while ((iterator.hasNext()) && (distinctNumber)) {
if (newNum == iterator.next()) {
distinctNumber = false;
}
}
}
}
combo.add(newNum);
}
printCombo();
return combo;
}
This is the method in my controller class.
public String execute() {
SortedSet<Integer> combo = new TreeSet<Integer>();
try {
if ((items == 0) || (maxNum == 0)) {
return "failure";
}
combo = Combo.createCombo(items, maxNum);
if (combo != null) {
HttpSession session = (HttpSession) request.getSession();
session.setAttribute("combo", combo);
}
return "success";
} catch (Exception e) {
}
return "failure";
}
This is my JSP. Only the text between the h1 tags appears in my browser.
<%@ page import="java.io.*"%>
<%@ page import="java.util.List"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<html>
<head>
<title>Lotto Results</title>
</head>
<body>
<center>
<h1>Lotto Results</h1>
</center>
<s:iterator value="combo">
<c:forEach var="iterator" items="${combo.iterator}" >
${iterator.next}
</c:forEach>
</s:iterator>
</body>
</html>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
combo 应该是 Action 类的一个属性,并且您应该有一个返回集合的方法
getCombo()
。然后将显示这些值。请参阅示例,我有一个名为 Song 的类和一个名为 AlbumInfoAction 的操作。
为了迭代,我应该将歌曲作为操作类的属性和方法 getSongs 应该存在。
JSP 代码如下所示
希望这会有所帮助。
combo should be a property of your Action class and you should have a method
getCombo()
which returns the collection. Then the values will be displayed.See the example, I've a class called Song and an Action called AlbumInfoAction
To iterate, I should have songs as a property of the action class and a method getSongs should be present.
The JSP code would look like this
Hope this helps.
我已经解决了我自己的问题。我删除了 s:iterator 标签,并将迭代循环保留在其中并将其更改为以下内容,并且这些更改起作用了。
I have solved my own problem. I removed the s:iterator tag, and I kept the iteration loop inside it and changed it to the following, and these changes worked.