javascript在appengine应用程序中给出内部服务器错误

时间:2015-02-23 12:49:54

标签: jquery google-app-engine internal-server-error

我正在为Google应用引擎开发一个网络应用程序。我在页面加载时使用jquery在jsp页面上填充下拉列表。下拉列表的值由servlet从数据库中检索。

之前该脚本工作正常,但现在它已经开始出现内部服务器错误。我已经尝试了很多来解决这个问题,但没有用。

这是代码。

</style>  
 <script   src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script> 
 <script type="text/javascript">
 $(document).ready(function() { 
    $.ajax({
        type: "POST",
        contentType: 'application/json; charset=utf-8',
        url:"/homeServlet",
        dataType: "json",
        async : false,
        success: function (data) {
            $.each(data.aaData,function(i,obj)
                   {
                       var div_data="<option             value="+obj.value+">"+obj.text+"</option>";
                       $(div_data).appendTo('#ch_user1'); 
                   });  
        },error : function(jqXHR, textStatus, errorThrown){
            alert("Error message "+errorThrown);
        }
    });
});

和servlet

package com.example.smartvault2;

import java.io.IOException;
 import java.io.PrintWriter;
 import java.sql.Connection;
  import java.sql.DriverManager;
 import java.sql.ResultSet;
import java.sql.Statement;
import javax.servlet.http.*;

 import com.google.appengine.api.utils.SystemProperty;
 import com.google.gson.JsonArray;
 import com.google.gson.JsonObject;

@SuppressWarnings("serial")
public class TestappServlet extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse resp)
        throws IOException {
    PrintWriter out=resp.getWriter();
    Connection conn;
    HttpSession session = req.getSession(true);
    String user=(String) session.getAttribute("user");
     JsonArray data_json=new JsonArray();
     String url = null;
     try
        {
            if (SystemProperty.environment.value() ==
                    SystemProperty.Environment.Value.Production) {
                  // Connecting from App Engine.
                  // Load the class that provides the "jdbc:google:mysql://"
                  // prefix.
                  Class.forName("com.mysql.jdbc.GoogleDriver");
                  url ="jdbc:google:mysql://smart-vault- 2:datavault/smartvault?user=root";
            }
            conn = DriverManager.getConnection(url);
             Statement st=conn.createStatement();
              ResultSet rs=st.executeQuery("select folder from folders where  username='"+user+"'");
              JsonObject json_response=new JsonObject();
              while(rs.next())
              {
                  JsonObject json=new JsonObject();
                  json.addProperty("value", rs.getString("folder").trim());
                  json.addProperty("text", rs.getString("folder").trim());
                  data_json.add(json);
              }
              json_response.add("aaData", data_json);
              resp.setContentType("application/Json");
              out.write(json_response.toString());

        }
        catch(Exception e)
        {

        }
}
}

请帮我理解这个问题。

0 个答案:

没有答案