2011-04-02 35 views
0

我想通過jsp中的jquery ajax請求來整合json。我正在使用org.json.simple包。客戶端的每一件事情都很好,但是從服務器響應中我得到了500個服務器代碼錯誤和4個readyState代碼。jsp json服務器:500錯誤

我得到的迴應是:

description The server encountered an internal error() that prevented it from fulfilling this request. 

exception 

org.apache.jasper.JasperException: Unable to compile class for JSP: 

An error occurred at line: 12 in the generated java file 
Only a type can be imported. org.json.simple.JSONObject resolves to a package 

An error occurred at line: 15 in the jsp file: /interceptor_primaryengine_save.jsp 
JSONObject cannot be resolved to a type 
12: <body> 
13: <% 
14: 
15: JSONObject obj = new JSONObject(); 
16: 
17: String value = request.getParameter("value"); 
18:  obj.put("value",value); 


An error occurred at line: 15 in the jsp file: /interceptor_primaryengine_save.jsp 
JSONObject cannot be resolved to a type 
12: <body> 
13: <% 
14: 
15: JSONObject obj = new JSONObject(); 
16: 
17: String value = request.getParameter("value"); 
18:  obj.put("value",value); 


Stacktrace: 

我用來發送響應的JSP代碼:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" 
    pageEncoding="ISO-8859-1"%> 
    <%@ page 
    import="org.jdom.*,java.util.*,org.jdom.input.SAXBuilder,org.jdom.output.XMLOutputter,java.io.*,org.jdom.filter.*,org.json.simple.JSONObject"%> 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> 
<title>Insert title here</title> 
</head> 
<body> 
<% 

    JSONObject obj = new JSONObject(); 

    String value = request.getParameter("value"); 
    obj.put("value",value); 
    out.print(value); 
    out.flush(); 
    %> 
</body> 
</html> 

我使用Eclipse IDE中。我已經在項目中導入了jar文件。我已經重新啓動服務器並重新啓動了eclipse。 我在這裏做錯了什麼?

+0

除了具體問題之外,您是否意識到您在此處將HTML與JSON混合在一起,並且您將JSON發送爲HTML? JSP在這裏是錯誤的工具。而是使用一個servlet。對於一些例子,檢查這個問題:http://stackoverflow.com/questions/4112686/update-current-page-with-a-servlet – BalusC 2011-04-02 21:00:02

回答

1

如果在發送響應的webapp的類路徑中找不到json-simple.jar,則可以獲取該消息。

+0

我也複製了lib文件夾裏的lib文件夾。我必須設置類路徑嗎?! – Maverick 2011-04-02 16:47:39

+0

好吧,我已經設置了類路徑,但沒有成功。 – Maverick 2011-04-02 16:50:17

+0

聽起來像你在正確的道路上。 jar文件應該位於WEB-INF/lib目錄中。在Eclipse中,右鍵單擊該項目並選擇屬性。選擇庫選項卡。你應該看到這個jar文件。如果沒有,請按添加JAR ...並添加它。該項目應該部署到您的應用服務器上,如果您的設置正確,那麼Eclipse可能會爲您做。 – 2011-04-02 20:30:15