我在尝试使 json 在 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)%>
<%
}
%>
我收到的错误是这样的
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我遇到了同样的问题,将 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
要么 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.我也遇到了同样的问题,请确保下载 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.