i am new to php and ajax..
the problem i am facing is -
i am displaying a table in a jsp page.. and i want to auto update the table without
refreshing the page at every 10 sec.
i am retrieving the values for the database from a php page..
here is the code for data.jsp
<html>
<script type="text/javascript">
function Ajax()
{
var
$http,
$self = arguments.callee;
if (window.XMLHttpRequest) {
$http = new XMLHttpRequest();
} else if (window.ActiveXObject) {
try {
$http = new ActiveXObject('Msxml2.XMLHTTP');
} catch(e) {
$http = new ActiveXObject('Microsoft.XMLHTTP');
}
}
if ($http) {
$http.onreadystatechange = function()
{
if (/4|^complete$/.test($http.readyState)) {
document.getElementById('ReloadThis').innerHTML = $http.responseText;
setTimeout(function(){$self();}, 10000);
}
};
$http.open('GET', 'getuser.jsp', true);
$http.send(null);
}
}
function myFunction()
{
setTimeout(function() {ajax();}, 10000);
}
</script>
</head>
<body>
<button onclick="myFunction()">Try it</button>
<div id="ReloadThis" > the table is to be shown here </div>
</body>
</html>
i wz doing the getuser part in php..but since tomcat doesnt supprt php.. so i converted my code to jsp.. and here is my code
and code for getuser.jsp
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.Connection"%>
<%
String cond="SELECT * FROM invertor ";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:xe");
PreparedStatement ps = con.prepareStatement(cond);
ResultSet rs = ps.executeQuery();
if (rs.next())
{
dc_volt = rs.getString(1).trim();
dc_amp = rs.getString(2).trim();
ac_volt = rs.getString(3).trim();
ac_amp = rs.getString(4).trim();
}
else
{
}
%>
and the error i am getting is java.lang.arrayindexoutofboundsexception:2
after triggering the "try": button from my data.jsp page.. no databse table is showing...