Reputation: 11751
I have a servlet to which I am posting data from ajax(jquery) call.
$('form').submit(function() {
var URL = "ProjectHandler";
var dataString=$(this).serialize();
$.ajax({
type: "POST",
url: URL,
data: dataString,
// dataType: json,
success: function(data)
{
alert(data.error);
}
});
return false;
});
I have commented dataType beacause when I uncomment it, it doesnt make ajax call, rather, the form is submitted with default mode i.e. the servlet is loaded
JAR's I have added to the project 1. json-lib-2.2.2-jdk15.jar 2. apache-commons-lang.jar 3. ezmorph-1.0.jar
first it threw exception filenotfound which was part of apache-commons package so included apache commons, after that I got exception of filenotfound which was part of ezmorph-1.0.jar, so I added that also. Now I am getting
java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory
Code in servlet doPost:
response.setContentType("application/json");
PrintWriter out = response.getWriter();
JSONObject json = new JSONObject();
json.put("error", true);
json.put("errorDesc", "wrong title");
out.print(json);
I hope I have cleared the scenario, any help would be appreciated.
Thanks
Upvotes: 0
Views: 2055
Reputation: 5916
Can you drop json-lib? If yes do it! Honestly there is no reason to use this library...the fact that it requires you to add tons of dependencies prooves it.
I would suggest you try Genson library http://code.google.com/p/genson/. It has the advantage to be easy to use but powerfull, extensible, all in one and fast. It would allow you to deserialize/serialize directly to pojos, no need to use all those JsonObject/Arrays... You can also directly use its streaming API if you need something close to manual json in term of performances.
Upvotes: 0
Reputation: 17940
It looks like you are missing the commons-logging.jar. Add it to your classpath.
Upvotes: 1