Reputation: 36404
<%@ 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)%>
<%
}
%>
the error I am getting is this
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");
How to debug this error ? I have downloaded the Json library and have put it in Tomcat/webapps/star/WEB-INF/lib.
Where star is the folder that contains the jsp page.
Upvotes: 4
Views: 7095
Reputation: 801
I had the same problem it is solved after i placed json libraries in WEB-INF\lib folder If you are using eclipse it helps to clean build once.
--Kiran.Kumar
Upvotes: 3
Reputation: 11
I also had the same problem, make sure you Download JSONLibraries and place it into Tomcat's lib directory . Also restart the server before executing your jsp file.
Upvotes: 1
Reputation: 1108782
Either the JSON library is not there where you think it is, or the JAR file of the JSON library which you've downloaded simply doesn't contain that class. Investigate the JAR file using a ZIP or RAR tool. There should be a net/sf/json/JSONArray.class
file inside the JAR. If it is missing, then you probably downloaded the wrong library.
Upvotes: 1