一个简单的Servlet+jsp+tomcat代码,无法与服务器交互,求大侠~
代码是照书上打得,零基础学JavaWeb开发, 环境是MyEclipse+tomcat6.0,jdk是1.7的,firefox和ie都能从服务器获取页面,但是按了按钮,或者这里的在文本框里输入什么的都没有反应,tomcat的log也没有任何反应,求指教~!~
Suggest.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>My JSP 'Suggest.jsp' starting page</title>
<script language="javascript">
function createXMLHttpRequest(){
if(window.XMLHttpRequest){
XMLHttpReq = new XMLHttpRequest();
}else{
if(window.ActiveXObject){
try{
XMLHttpReq = new ActiveXObject("Msxm12.XMLHTTP");
}catch(e){
try{
XMLHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
}catch(e){}
}
}
}
}
function handleResponse(){
if(XMLHttpReq.readyState==4){
if(XMLHttpReq.status ==200){
var out = "";
var res = XMLHttpReq.responseXML;
var items = res.getElementsByTagName("item");
for(var i=0;i<items.length;i++){
addRow(items(i).firstChild.nodeValue);
}
setDivStyle();
}
}
}
function clearTable(){
var content = document.getElementById("content");
while(chontent.childNodes.length>0){
content.removeChild(content.childNodes[0]);
}
}
function addRow(item){
var content = document.getElementById("content");
var row = document.createElement("tr");
var cell = document.createElement("td");
cell.onmouseover = function(){this.style.background = "blue"};
cell.onmouseout = function(){this.style.background = "#f5f5f1"};
cell.onclick = function(){
document.getElementById("key").value = this.innerHtml;
document.getElementById("suggest").style.visibility = "hidden"};
row.appendChile(cell);
content.appendChild(row);
}
function sendRequest(url){
createXMLHttpRequest();
XMLHttpReq.open("GET",url,true);
XMLHttpReq.inreadystatechange = handleResponse;
XMLHttpReq.send(null);
}
function suggest(){
var key = document.getElementById("key").value;
sendRequest("Suggest?key="+key);
}
function setDivStyle(){
var suggest = document.getElementById("suggest");
suggest.style.border = "black 1px solid";
suggest.style.left = 62;
suggest.style.top = 50;
suggest.style.width = 150