当前位置: 代码迷 >> Java Web开发 >> 急 差点砸电脑了 !一个最简单的AJAX例子 如何跑不起来
  详细解决方案

急 差点砸电脑了 !一个最简单的AJAX例子 如何跑不起来

热度:71   发布时间:2016-04-17 12:56:26.0
急,急,急 差点砸电脑了 !一个最简单的AJAX例子 怎么跑不起来
JSP部分:
<%@   page   language= "java "   import= "java.util.* "   pageEncoding= "utf-8 "%>
<!DOCTYPE   html   PUBLIC   "-//W3C//DTD   XHTML   1.0   Transitional//EN "   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<html>
<head>
<title> 无标题文档 </title>
<script   language= "javascript ">
var   XMLHttpReq   =   new   ActiveXObject( "MSXML2.XMLHTTP.3.0 ");
function   callServer()   {
    XMLHttpReq.open( "GET ",   "servlet/ajax_sevelet ",   "true ");
    XMLHttpReq.onreadystatechange   =   updatePage;
    XMLHttpReq.send(null);
}
  function   send_msg(){

  callServer();
  }
</script>
</head>

<body>
<form   id= "form1 "   name= "form1 "   method= "post "   action= " ">
    姓名: <label>
    <input   type= "text "   ondblclick= "send_msg() "   name= "name "   />
    </label> <p>
    密码: <label>
    <input   type= "text "     name= "password "   />
    </label>
</form>
<a   href= "servlet/ajax_sevelet "> ei </a> /*   点这里可以调用sevlet,证明路径没错啊
</body>
</html>
sevlet部分:
package   shiyan;

import   java.io.BufferedReader;
import   java.io.BufferedWriter;
import   java.io.FileReader;
import   java.io.FileWriter;
import   java.io.IOException;
import   java.io.PrintWriter;

import   javax.servlet.ServletException;
import   javax.servlet.http.HttpServlet;
import   javax.servlet.http.HttpServletRequest;
import   javax.servlet.http.HttpServletResponse;

public   class   ajax_sevelet   extends   HttpServlet   {

/**
  *   Destruction   of   the   servlet.   <br>
  */
public   void   destroy()   {
super.destroy();   //   Just   puts   "destroy "   string   in   log
//   Put   your   code   here
}


public   void   doGet(HttpServletRequest   request,   HttpServletResponse   response)
throws   ServletException,   IOException   {
          doPost(request,response);
}


public   void   doPost(HttpServletRequest   request,   HttpServletResponse   response)
throws   ServletException,   IOException   {
int   i=1;

response.setContentType( "text/html ");
PrintWriter   out   =   response.getWriter();
String   name=request.getParameter( "name ");
System.out.println(i+ "调用成功 "+name);
}


public   void   init()   throws   ServletException   {
//   Put   your   code   here
}

}
web.xml部分:
<?xml   version= "1.0 "   encoding= "UTF-8 "?>
<web-app   version= "2.4 "  
  相关解决方案