tags:

views:

79

answers:

1

I'm just starting to learn JSP (and I'm pretty new to Java in general), and I'd like to use JSON-lib with it. I want to make a page something like this:

<%@ page import="net.sf.json.JSONObject"%>
<%
String json = new JSONObject().put("hello", "world").toString();
out.println(json);
%>

I downloaded json-lib-2.3-jdk15.jar and put it in the same directory as the .jsp page. But I get this error

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: 

How do I make the JSONObject class available to my .jsp page?

+3  A: 

You need to deploy that jar file with your web application. Usually you have to put it in WEB-INF/lib/ folder.

Toader Mihai Claudiu
Thanks! I'm really completely new at this--I don't know what it means to "deploy that jar file with your web application". I found the WEB-INF/lib folder and put the .jar there, but that didn't seem to help anything.
Matthew
well .. depending on how your application server is setup up you might need to redeploy the application. But if this seems stange to you (you don't know what this means) you should follow BalusC's link: http://courses.coreservlets.com/Course-Materials/csajsp2.html and start learning from there.
Toader Mihai Claudiu