我在jsp中访问我的java类时遇到了麻烦。
在jsp中:
<%@ page import="package.ClientWithResponseHandler" %>
<% ClientWithResponseHandler jira = new ClientWithResponseHandler();
System.out.println(jira.getJIRA()); %>
在java中:
public class ClientWithResponseHandler {
public String getJIRA() throws Exception {
String string="";
HttpClient httpclient = new DefaultHttpClient();
HttpGet httpget = new HttpGet("someURL");
ResponseHandler<String> responseHandler = new BasicResponseHandler();
String[] responseBody = httpclient.execute(httpget, responseHandler).replace("[", "").replace("}]","").split("},");
for (int i=0;i<responseBody.length;i++)
{
responseBody[i]+="}";
JSONObject project= new JSONObject(responseBody[i]);
string +=project.getString("name");
string+="||";
String url=project.getString("self");
HttpGet httpget2 = new HttpGet(url);
String responseBody2 = httpclient.execute(httpget2, responseHandler);
JSONObject taskall= new JSONObject(responseBody2);
JSONArray tasks=taskall.getJSONArray("components");
for(int j=0;j<tasks.length();j++)
{
JSONObject task= tasks.getJSONObject(j);
string+=task.getString("name");
string+="|";
}
}
return string;
}
}
通过调用getJIRA()方法,我希望它返回一个我休息的数据字符串。我检查了它,我认为java类确实正常工作并返回一个字符串。当我运行我的jsp页面时,会抛出异常:
HTTP Status 500 - An exception occurred processing JSP page /index.jsp at line 23
23: <% ClientWithResponseHandler jira = new ClientWithResponseHandler();
javax.servlet.ServletException: java.lang.NoClassDefFoundError: org/apache/http/client/ResponseHandler
java.lang.NoClassDefFoundError: org/apache/http/client/ResponseHandler
java.lang.ClassNotFoundException: org.apache.http.client.ResponseHandler
我对编程很新,所以我不知道这是什么意思。如果有人能帮助我,我会非常感激。
答案 0 :(得分:0)
似乎您的Apache HTTP Client JAR不在您的Web应用程序类路径中。尝试检查它是否位于WAR文件中的WEB-INF/lib
文件夹中。