An error occurred trying to run json in a jsp page. How to debug this?

advertisements
<%@ 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.


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.