我在尝试使 json 在 jsp 页面中工作时遇到错误。如何调试这个?

发布于 2024-10-05 23:02:37 字数 1579 浏览 1 评论 0原文

<%@ 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 页面的文件夹。

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

清浅ˋ旧时光 2024-10-12 23:02:38

我遇到了同样的问题,将 json 库放入 WEB-INF\lib 文件夹后解决了
如果您使用 Eclipse,它有助于清理一次构建。

——基兰·库马尔

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

旧时模样 2024-10-12 23:02:38

要么 JSON 库不在您认为的位置,要么您下载的 JSON 库的 JAR 文件根本不包含该类。使用 ZIP 或 RAR 工具调查 JAR 文件。 JAR 内应该有一个 net/sf/json/JSONArray.class 文件。如果丢失,那么您可能下载了错误的库。

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.

孤独陪着我 2024-10-12 23:02:38

我也遇到了同样的问题,请确保下载 JSONLibraries 并将其放入 Tomcat 的 lib 目录中。另外,在执行 jsp 文件之前重新启动服务器

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文