(json学习二)使用json需要导入的jar包_Json
《greenboy:》使用json需要导入的jar包(这个需要先了解下,避免写工程的时候,出现的问题很多,我自己调试了两个小时 哎 悲哀啊)json-lib-2.3-jdk15.jar
commons-beanutils-1.7.0.jar
commons-httpclient-3.1.jar
commons-lang-2.3.jar
commons-logging-1.0.4.jar
commons-collections-3.1.jar
ezmorph-1.0.3.jar
这些包可以从一下地方下载:
http://commons.apache.org/index.html
http://json-lib.sourceforge.net/
http://ezmorph.sourceforge.net/
http://www.docjar.com/
如果不关联这些包,则会出现以下错误:
java.lang.NoClassDefFoundError: net/sf/ezmorph/Morpher
java.lang.NoClassDefFoundError: org/apache/commons/collections/map/ListOrderedMap
java.lang.NoClassDefFoundError: org/apache/commons/beanutils/DynaBean
java.lang.NoClassDefFoundError: org/apache/commons/codec/DecoderException
java.lang.NoClassDefFoundError: org/apache/commons/lang/exception/NestableRuntimeException
java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
package com.json;
public class User {
String username;
String password;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
package com.json;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import net.sf.json.JSONArray;
public class TestJson extends HttpServlet {
public void doGet(Ht