I want to just show my data from database on div notifications using Ajax but it doesn't work. I am using Maven and Spring, Hibernate and in this code I am using only JDBC, just to see if it's working or not. But it doesn't give any output.
function getNotifications() {
var xmlHttp;
try {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {
try {
xmlHttp = new XMLHttpRequest();
} catch (e) {
alert("your browser cant support");
}
}
xmlHttp.onreadystatechange = function () {
if (xmlHttp.readyState == 4) {
var x = (xmlHttp.responseText);
document.getElementById("notifications").innerHTML = x;
/* document.write(xmlHttp.responseText); */
}
}
var url = "auto.jsp";
url = url + "?q=" + str;
xmlHttp.open("get", url, true);
xmlHttp.send(url);
}
auto.jsp
<%@ page import="java.sql.*" %>
<% String s="G";
System.out.println("helloooooooooo1111111");
String result="";
ArrayList li = new ArrayList();
try {
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/db2402","root","admin");
System.out.println("helloooooooooo1111111");
Statement st = con.createStatement();
String sql = "select * from message ";
System.out.println("helloooooooooo22222266666");
st.execute(sql);
ResultSet rs = st.getResultSet();
System.out.println("helloooooooooo222222");
int i = 1;
while(rs.next()){
li.add(rs.getString(i));
i = i++;
}
}
catch(Exception ex){
out.println(ex);
}
%>
<%
Iterator itr = li.iterator();
while (itr.hasNext()) {
out.println(itr.next());
}
%>