当前位置: 代码迷 >> Java Web开发 >> 一个容易的Servlet+jsp+tomcat代码,无法与服务器交互,求大侠
  详细解决方案

一个容易的Servlet+jsp+tomcat代码,无法与服务器交互,求大侠

热度:3559   发布时间:2013-02-25 21:10:15
一个简单的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;
  suggest.style.backgroundColor = "#f5f5f1";
  document.getElementById("suggest").style.visibility = "visible";
  相关解决方案
本站暂不开放注册!
内测阶段只得通过邀请码进行注册!