我有简单的 servlet 供码头使用。
这是我的 servlet 的片段:
import org.json.simple.JSONObject;
import org.json.simple.JSONValue;
public class Oscar4Servlet extends HttpServlet
{
...
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException
{
request.setCharacterEncoding("utf8");
response.setCharacterEncoding("utf8");
response.setContentType("application/json");
PrintWriter out = resp.getWriter();
JSONObject obj = new JSONObject();
obj.put("message", "hello from server");
out.print(obj);
}
}
调用后:
javac -cp /usr/share/jetty/lib/servlet-api-2.5.jar Oscar4Servlet.java
我收到此错误:
Oscar4Servlet.java:5: error: package org.json.simple does not exist
import org.json.simple.JSONObject;
^
Oscar4Servlet.java:6: error: package org.json.simple does not exist
import org.json.simple.JSONValue;
虽然我的目录中有json-simple-1.1.1.jar
(从http://code.google.com/p/json-simple/downloads/detail?name=json-simple-1.1.1.jar下载)WEB_INF/lib
......有什么想法吗?