package com.test.tags;
import java.io.IOException;
import java.util.*;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.SimpleTagSupport;
import com.sun.xml.internal.bind.v2.schemagen.xmlschema.List;
public class ForEachListTag extends SimpleTagSupport {
private List items;
private String var;
public void setItems(List items) {
this.items = items;
}
public void setVar(String var) {
this.var = var;
}
public void doTag() throws JspException, IOException {
for (Object obj : items) {
this.getJspContext().setAttribute(var, obj);
this.getJspBody().invoke(null);
}
}
}
我创建了一个List变量items,使用foreach遍历,编译器在最后一个items报错Can only iterate over an array or an instance of java.lang.Iterable
我想知道这个写法不对吗应该怎么修改,使用的是java8