开发者

How do I make a third party .jar available to my .jsp page?

I'm ju开发者_开发百科st 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?


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


I ran into a similar problem trying to import net.sf.json.JSONArray and got the same error. But when I replaced "JSONArray" with an asterisk, "*", the error went away. Of course, you need to put the JSON-lib.jar file into your {appdir}/WEB-INF/lib directory. [I still have other associated problems with the JSON-lib being used in my JSP, so I'm not sure my answer is all you need.]

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜