AJAX为什么拿不到值,大家帮我看看错在哪?
result.jsp
--------------------
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" import="java.util.*"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<script>
function GetResult(){
if(window.XMLHttpRequest) {
var xmlhttp = new XMLHttpRequest();
}
else if(window.ActiveXObject) {
var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET","getresult.jsp",true);
xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
xmlhttp.send("null");
var strResult = xmlhttp.responseText;
alert(strResult);
}
function MyShow(){
timer = window.setInterval("GetResult()",2000);
}
</script>
<body onload='GetResult()'>
<p></p>
<table width="47%" height="23" border="0" cellpadding="1"
cellspacing="0" id="tb">
<tr>
<td>num1</td>
<td>num2</td>
</tr>
</table>
</body>
</html>
------------------------------------------------------------------------
getresult.jsp
---------------------------------
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" import="java.sql.*" import="java.util.*"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
String url = "jdbc:mysql://localhost:3306/good";
String name = "root";
String password = "";
Connection con = DriverManager.getConnection(url, name,
password);
Statement stmt = con.createStatement();
ResultSet rs = stmt
.executeQuery("select * from title");
while (rs.next()) {
response.getWriter().write(rs.getString("content"));
System.out.println(rs.getString("content"));
}
} catch (Exception e) {
e.printStackTrace();
}
%>
</body>
</html>