The error I received while trying to get json to work on the jsp page. How to debug this?

<%@ 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 get 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 downloaded the Json library and put it in Tomcat / webapps / star / WEB-INF / lib.

Where star is the folder containing the jsp page.

+3
source share
3 answers

Either the JSON library is not where you think it is, or the JSON library JAR file that you downloaded simply does not contain this class. Examine the JAR file with the ZIP or RAR tool. There must be a file in the JAR net/sf/json/JSONArray.class. If it is missing, you are likely to load the wrong library.

+1
source

, json- WEB-INF\lib eclipse, .

- Kiran.Kumar

+2

I also had the same problem, make sure you download JSONLibraries and put it in the Tomcat lib directory. Also reboot the server before running the jsp file.

+1
source

Source: https://habr.com/ru/post/1777681/


All Articles