Shi*_*ibu 1 json jsp portlet servlets liferay
Map countryList = new HashMap();
String str = "http://10.10.10.25/TEPortalIntegration/CustomerPortalAppIntegrationService.svc/PaymentSchedule/PEPL/Unit336";
try {
URL url = new URL(str);
URLConnection urlc = url.openConnection();
BufferedReader bfr = new BufferedReader(new InputStreamReader(
urlc.getInputStream()));
String line, des;
double title;
final StringBuilder builder = new StringBuilder(2048);
while ((line = bfr.readLine()) != null) {
builder.append(line);
}
// convert response to JSON array
final JSONArray jsa = new JSONArray(builder.toString());
// extract out data of interest
for (int i = 0; i < jsa.length(); i++) {
final JSONObject jo = (JSONObject) jsa.get(i);
title = jo.getDouble("NetAmount");
countryList.put(i, title);
}
System.out.println(countryList); /* Giving result if i run in Console*/
} catch (Exception e) {
// TODO: handle exception
}
renderRequest.setAttribute("out-string", countryList);
Run Code Online (Sandbox Code Playgroud)
上面的代码是从Java客户端使用JSON Web服务.我可以从java控制台应用程序访问它.但是当尝试使用JSP或Liferay时它不起作用.在JSP中它给出java.lang.NoClassDefFoundError:org/json/JSONArray.请帮我修理一下.我是否需要将更多jar文件添加到库中以使其在JSP中运行?
您需要JSONArray
根据此目录结构在Web应用程序中添加包含类的jar文件:
Tomcat_HOME
->
webapps
->
YourWebAppName
->
WEB-INF
->lib
->Here goes your jar file
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1552 次 |
最近记录: |