Hi, I have read many documentations and followed the procedure told by them....in order to convert a map in to JSONObject i wrote the following code..
import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import net.sf.json.JSONArray; import net.sf.json.JSONObject; public class input extends HttpServlet { private static final long serialVersionUID = 1L; public input() { super(); } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doPost(request,response); } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { User user=new User(); PrintWriter out = response.getWriter(); System.out.println((user.getMap().get("firstname"))); System.out.println((user.getMap().get("age"))); out.print((user.getMap().get("firstname"))); out.print((user.getMap().get("age"))); Map map=user.getMap(); JSONObject obj=JSONObject.fromObject(map); System.out.println(obj.toString()); } }
The values from the map are read correctly when i use normal methods...the problem is converting it in to JSONObject
and on executing Iam getting the following errors on stack trace.
Sep 2, 2010 8:23:52 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet input threw exception
java.lang.NoClassDefFoundError: org/apache/commons/collections/map/MultiKeyMap at net.sf.json.JsonConfig.(JsonConfig.java:56) at net.sf.json.JSONArray.fromObject(JSONArray.java:120) at input.doPost(input.java:46) at javax.servlet.http.HttpServlet.service(HttpServlet.java:710) at javax.servlet.http.HttpServlet.service(HttpServlet.java:803) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447) at java.lang.Thread.run(Thread.java:619)
i have included the follwing jar files in the path
commons-lang.jar commons-logging.jar commons-beanutils.jar ezmorph-1.0.1.jar json-lib-1.1-jdk15.jar commons-collection 3.1.jar
Kindly suggest me a way out....i tried implementing a generic pojo to JSONObject converter but its not working i tried using jacksons-mapper too still no luck ..please help me...