servlet的代码如下: public void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException { System.out.println("XXXXXXXXXXX"); response.setContentType("text/plain;charset=UTF-8"); PrintWriter out=response.getWriter(); System.out.println("现在的时间是:"+getCurrentDateAndTime()+"欢迎您(helloworld)"); out.write("现在的时间是:"+getCurrentDateAndTime()+"欢迎您(helloworld)"); out.close(); System.out.println("EEEEEEEEEEEEEEEEEEE"); } private String getCurrentDateAndTime() { String currentDate=""; SimpleDateFormat format1=new SimpleDateFormat("yyyy'-'MM'-'dd HH:mm:ss"); format1.setLenient(false); currentDate=format1.format(new Date()); return currentDate; }
$.ajax({ type: "POST", url: "some.php", data: "name=John&location=Boston", success: function(msg){ alert( "Data Saved: " + msg ); }});其中 success: function(msg) 的 msg 就是servlet 传回的值
以jquery ajax为例$.ajax({ url: '你的请求地址', success: function(result){ //result就是返回的结果,看你接收什么样的返回类型,可以为text,json,xml等等 } });