I have a servlet that takes a parameter from the request and sends a JsonObject as a response.
My problem that every time that I tried to use the PrintWriter class (I tried even to print simple string as a test), the servlet starts but never returns a response. My second problem is that I get the following exception:
java.lang.ClassNotFoundException: org.json.JSONObject
What package contains the JsonObject?
The servlet code:
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String user = request.getParameter("param1"); // I need this later ...
System.out.println("do get called ");
response.setContentType("application/json");
response.setCharacterEncoding("utf-8");
PrintWriter out = response.getWriter();
org.json.JSONObject json = new org.json.JSONObject();
try {
json.put("Mobile",123);
json.put("Name", "ManojSarnaik");
out.print(json.toString());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
out.flush();
} finally{
out.flush();
}
}
org.jsonpackage) is: github.com/douglascrockford/JSON-java