仅在openshift上获取错误

时间:2015-02-21 11:29:43

标签: java javascript jsp

在我的java应用程序中,我从mysql数据库中获取一些细节。但是当使用netbeans和Apache tomcat在我的localhost上运行时,它运行正常。但我也在Openshift中部署了相同的内容,当我运行相同的页面(Add_Details.jsp)时,它在控制台(浏览器控制台)上抛出一个错误,如下所示: 注意:我面临错误的页面,我使用过ja

 Uncaught TypeError: Cannot read property 'status' of null

在按钮上单击Add_Details.jsp页面我使用ajax和JSON执行此操作:

$.ajax({
                            url: "Insertst",
                            type: "post",
                            data: {
                                name: $("#name").val().trim(),
                                key: $("#ukey").val().trim()
                            },
                            success: function(msg)
                            {
                                if (msg.status === "success")
                                {
                                    $("#errordiv").css("color", "green");
                                    document.getElementById("errordiv").innerHTML = "Data Inserted!";
                                    $("#errordiv").fadeIn("fast").delay(2000).fadeOut("slow");
                                    $("#name").val("");
                                    $("#ukey").val("");
                                }
                                else
                                {
                                    document.getElementById("errordiv").innerHTML = "Error Occured! = " + msg.error;
                                }
                            }
                        });

在数据库端我正在这样做:

PreparedStatement ps = con.prepareStatement(sql);

            ps.setString(1, obj.getString("name"));
            ps.setString(2, Base64.getEncoder().encodeToString(secretKey.getEncoded()));
            n = ps.executeUpdate();
            res = new JSONObject();
            if(n != 0)
            {
                res.put("status", "success");
            }
            else
            {
                res.put("status", "failed");
            }
        }        
        catch(Exception ex)
        {
            res = new JSONObject();
            res.put("status", "failed");
            res.put("error", ex);
            System.out.println(getClass().getName()+" = " +ex.toString());
        }
        finally
        {
            try {
                dc.closeConnection();
                con.close();
            } 
            catch (SQLException ex) {
                System.out.println(getClass().getName()+" = " +ex.toString());
            }
            return res;
        }

请帮助我,为什么我只在Openshift上收到此错误。

Ajax调用将数据存储到数据库(Add_Details.JSP)

$(document).ready(function() {
                $("#submit").click(function() {
                    var x = $("#name").val();
                    if (x === null || x === "")
                    {
                        document.getElementById("errordiv1").innerHTML = "Required Feild!";

                    }
                    else if ($("#uname").val() === null || $("#uname").val() === "")
                    {
                        document.getElementById("errordiv1").innerHTML = "";
                        document.getElementById("errordiv2").innerHTML = "Required Feild!";
                    }
                    else if ($("#upass").val() === null || $("#upass").val() === "")
                    {
                        document.getElementById("errordiv2").innerHTML = "";
                        document.getElementById("errordiv3").innerHTML = "Required Feild!";
                    }
                    else if ($("#ukey").val() === null || $("#ukey").val() === "")
                    {
                        document.getElementById("errordiv3").innerHTML = "";
                        document.getElementById("errordiv4").innerHTML = "Required Feild!";
                    }
                    else if (result1 === false)
                    {
                        document.getElementById("errordiv").innerHTML = "Enter valid Data";
                    }
                    else if (result2 === false)
                    {
                        document.getElementById("errordiv").innerHTML = "Enter valid Data";
                    }
                    else
                    {
                        document.getElementById("errordiv1").innerHTML = "";
                        document.getElementById("errordiv2").innerHTML = "";
                        document.getElementById("errordiv3").innerHTML = "";
                        document.getElementById("errordiv4").innerHTML = "";
                        $.ajax({
                            url: "InsertServlet",
                            type: "post",
                            data: {
                                uniqueID: $("#uniqueID").val(),
                                name: $("#name").val().trim(),
                                username: $("#uname").val().trim(),
                                password: $("#upass").val().trim(),
                                key: $("#ukey").val().trim(),
                                link: $("#ulink").val().trim(),
                                saveKey: saveKey
                            },
                            success: function(msg)
                            {
                                if (msg.status === "success")
                                {
                                    $("#errordiv").css("color", "green");
                                    document.getElementById("errordiv").innerHTML = "Data Inserted!";
                                    $("#errordiv").fadeIn("fast").delay(2000).fadeOut("slow");
                                    $("#name").val("");
                                    $("#uname").val("");
                                    $("#upass").val("");
                                    $("#ukey").val("");
                                    $("#ulink").val("");
                                }
                                else
                                {
                                    document.getElementById("errordiv").innerHTML = "Error Occured! = " + msg.error;
                                }
                            }
                        });
                    }
                });
            });

0 个答案:

没有答案