<%@ page language="java" import="net.sf.json.JSONArray" %> <% JSONArray arrayObj=new JSONArray(); arrayObj.add("MCA"); arrayObj.add("Amit Kumar"); arrayObj.add("19-12-1986"); arrayObj.add(24); arrayObj.add("Scored"); arrayObj.add(new Double(66.67)); %> <h2>Array Object is =></h2> <%=arrayObj%> <br><hr> <% for(int i=0;i<arrayObj.size();i++){ %> <%=arrayObj.getString(i)%> <% } %>
我得到的错误是
org.apache.jasper.JasperException: Unable to compile class for JSP: An error occurred at line: 6 in the generated java file Only a type can be imported. net.sf.json.JSONArray resolves to a package An error occurred at line: 19 in the jsp file: /index.jsp JSONArray cannot be resolved to a type 16: <%@ page language="java" import="net.sf.json.JSONArray" %> 17: 18: <% 19: JSONArray arrayObj=new JSONArray(); 20: arrayObj.add("MCA"); 21: arrayObj.add("Amit Kumar"); 22: arrayObj.add("19-12-1986"); An error occurred at line: 19 in the jsp file: /index.jsp JSONArray cannot be resolved to a type 16: <%@ page language="java" import="net.sf.json.JSONArray" %> 17: 18: <% 19: JSONArray arrayObj=new JSONArray(); 20: arrayObj.add("MCA"); 21: arrayObj.add("Amit Kumar"); 22: arrayObj.add("19-12-1986");
如何调试此错误?我已经下载了Json库,并将其放在Tomcat / webapps / star / WEB-INF / lib中。
其中star是包含jsp页面的文件夹。
JSON库不在您认为的位置,或者您下载的JSON库的JAR文件根本不包含该类。使用ZIP或RAR工具调查JAR文件。net/sf/json/JSONArray.classJAR内应有一个文件。如果缺少该库,则可能是下载了错误的库。
net/sf/json/JSONArray.class