我尝试在JSP中创建arrayList方法如下:
<%!
public int x = 0;
public ArrayList array = new ArrayList();
array.add(new ArrayList());
public ArrayList cidTime (int cid, int w)
{
((ArrayList)array.get(x)).add(cid);
((ArrayList)array.get(x)).add(w);
x++;
return array;
}
%>
但它返回错误:
Syntax error on token(s), misplaced construct(s)
Syntax error on token "add", = expected after this token
有什么建议吗?
您正在使用 JSP 声明标记<%!
。根据此处的信息,它将声明和方法放在 JSP 页面的service
方法主体之外。这意味着您的调用array.add(new ArrayList());
导致了问题,因为它不是变量声明或方法声明。