我刚开始学习 JSP(总的来说,我对 Java 还很陌生),我想使用 JSON-lib用它。我想制作这样的页面:
<%@ page import="net.sf.json.JSONObject"%>
<%
String json = new JSONObject().put("hello", "world").toString();
out.println(json);
%>
我下载了json-lib-2.3-jdk15.jar,放在和.jsp页面同级目录下。但是我得到了这个错误
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.JSONObject resolves to a package
An error occurred at line: 3 in the jsp file: /getCard.jsp
JSONObject cannot be resolved to a type
1: <%@ page import="net.sf.json.JSONObject" %>
2: <%
3: String json = new JSONObject().put("hello", "world").toString();
4: out.println(json);
5: %>
6:
如何使 JSONObject 类可用于我的 .jsp 页面?
最佳答案
您需要使用您的 Web 应用程序部署该 jar 文件。通常你必须把它放在 WEB-INF/lib/文件夹中。
关于java - 如何使第三方 .jar 可用于我的 .jsp 页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2985206/