前台先寫好ajax
<script> $.ajax({ url : "newsservlet",//請求地址 dataType : "json",//數據格式 type : "post",//請求方式 async : true,//是否異步請求 success : function(data) { //data是服務器返回數據 alert(data); }, }); </script>
后台
PrintWriter out=response.getWriter(); String a="aaa"; out.write(a.toString());
頁面顯示