Json lib集成stucts2的使用方法 抛出 NestableRuntimeException异常的解决办法

时间:2023-03-09 13:10:12
Json lib集成stucts2的使用方法    抛出 NestableRuntimeException异常的解决办法

首先贴出struts 2.3.16需要导入的包

Json lib集成stucts2的使用方法    抛出 NestableRuntimeException异常的解决办法

因为使用的是2.3 版本,必须要导入这个包,否则会报java.lang.NoClassDefFoundError: org/apache/commons/lang3/StringUtils异常。

JSONObject 的使用

项目中导入了 json-lib 包,但是在运行如下代码的时候还是出现了如下错误,究其原因是因为缺包,缺了如下5个包:

commons-beanutils-1.8.3

commons-lang-2.6 (注:导入最新的 3.1 版本会继续报如下错误   所以 需要在同时导入commons-lang-2.6 )

commons-collections-3.2.1

commons-logging-1.1.1

ezmorph-1.0.6

Json Lib 下载:json-lib-2.4

import net.sf.json.JSONObject;

public class TestJson {
public static void main(String[] args){
Map<String, String> map = new HashMap<String, String>();
map.put("key", "value");
map.put("name", "abc");
JSONObject json = JSONObject.fromObject(map);
System.out.println(json);
}
}

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/lang/exception/NestableRuntimeException

......

Caused by: java.lang.ClassNotFoundException: org.apache.commons.lang.exception.NestableRuntimeException

......