我刚刚开始学习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 /文件夹中。