我连接到MySQL后端的JSP代码返回一个空白页面

时间:2016-10-17 13:41:49

标签: mysql ajax html5 jsp

以下AJAX代码不起作用。它不会加载指定的div元素中的任何表。请帮帮我哪里出错了。

提前致谢。

JavaScript AJAX代码:

function showDetail(){
    var str=document.getElementById("p_id").value;
    var obj1=new XMLHttpRequest();

    obj1.onreadystatechange=function(){
        if(obj1.readyState==4 && obj1.status=200)
            {
                document.getElementById("fillarea").innerHTML=obj1.responseText;
            }
    }

    obj1.open("GET","gettable.jsp?q="+str,true);
    obj1.send();
}

gettable.jsp      我从SQL表" patdet"中检索了值。 Follwing是代码:

<body>
<%
    String p_id = request.getParameter("q");

        try {
            Class.forName("com.mysql.jdbc.Driver");
            Connection con= DriverManager.getConnection("jdbc:mysql://localhost:3306/hms1","root","vigneshbabu");
            PreparedStatement pst=con.prepareStatement("select p_id,p_name,age,app_time,app_date,treatment,diagnosis from patdet where p_id=?");
            pst.setString(1,p_id);
            ResultSet rs = pst.executeQuery();

            out.print("<table border=1>");
            out.print("<tr>");
            out.print("<td>Patient_id</td>");
            out.print("<td>"+rs.getInt(1)+"</td>");
            out.print("</tr>");

            out.print("<tr>");
            out.print("<td>Age</td>");
            out.print("<td>"+rs.getString(2)+"</td>");
            out.print("</tr>");


            out.print("<tr>");
            out.print("<td>Appointment date</td>");
            out.print("<td>"+rs.getString(3)+"</td>");
            out.print("</tr>");

            out.print("<tr>");
            out.print("<td>Appointment time</td>");
            out.print("<td>"+rs.getString(4)+"</td>");
            out.print("</tr>");

            out.print("<tr>");
            out.print("<td>Diagnosis</td>");
            out.print("<td>"+rs.getString(5)+"</td>");
            out.print("</tr>");

            out.print("<tr>");
            out.print("<td>Treatment</td>");
            out.print("<td>"+rs.getString(6)+"</td>");
            out.print("</tr>");

            out.print("<tr>");
            out.print("<td>Patient name</td>");
            out.print("<td>"+rs.getString(7)+"</td>");
            out.print("</tr>");

            out.print("</table>");

            rs.close();

            pst.close();

        }

        catch (SQLException sqe)
        {
            out.println(sqe);
        }
%>

0 个答案:

没有答案