課程
/前端開發(fā)
/JavaScript
/Ajax全接觸
有人用jsp做這個(gè)案例成功了嗎?有的話可以分享給我參考看看嗎
2018-06-12
源自:Ajax全接觸 3-2
正在回答
我也是剛剛看到這里,我只做了一個(gè)小的模仿,只做了第一小題的簡(jiǎn)化版,關(guān)鍵點(diǎn)在于前后端的數(shù)據(jù)是如何傳遞的,理解了第一題我覺得第二題肯定也不會(huì)太難做,希望能夠幫到你。
????????????????????????????這是后端的servlet代碼,我寫的很簡(jiǎn)單,希望不要嫌棄。
????????????????????????
前端代碼:
<%@?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%>"> ???? ????<title>My?JSP?'index.jsp'?starting?page</title> <meta?http-equiv="pragma"?content="no-cache"> <meta?http-equiv="cache-control"?content="no-cache"> <meta?http-equiv="expires"?content="0">???? <meta?http-equiv="keywords"?content="keyword1,keyword2,keyword3"> <meta?http-equiv="description"?content="This?is?my?page"> <!-- <link?rel="stylesheet"?type="text/css"?href="styles.css"> --> <script?type="text/javascript"> window.onload=function(){ document.getElementById("username").onblur=function(){ var?xmlhttp?=?null; if(window.XMLHttpRequest) xmlhttp?=?new?XMLHttpRequest(); else xmlhttp?=?new?ActiveXObject("Microsoft.XMLHTTP"); xmlhttp.open("GET",?"http://localhost:8080/myfirstwebapp/cat?username="+document.getElementById("username").value.toString()); xmlhttp.send(); xmlhttp.onreadystatechange?=?function(){ if(xmlhttp.readyState==4&&xmlhttp.status==200) document.getElementById("queryUserName").innerHTML?=?xmlhttp.responseText; }; } document.getElementById("username").onfocus=function(){ document.getElementById("queryUserName").innerHTML?=?""; } } </script> ??</head> ?? ??<body> ????<h2?style="color:red;">測(cè)試ajax程序</h2> ????<form?action=""> ????用戶名:<input?id="username"?type="text"?name="username"> ????<span?id="queryUserName"?style="color:red;"></span> ????</form> ??</body> </html>
舉報(bào)
本課程通過一個(gè)案例,講解Ajax的相關(guān)概念原理實(shí)現(xiàn)方式和應(yīng)用
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號(hào)-11 京公網(wǎng)安備11010802030151號(hào)
購課補(bǔ)貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動(dòng)學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號(hào)
2018-06-17
我也是剛剛看到這里,我只做了一個(gè)小的模仿,只做了第一小題的簡(jiǎn)化版,關(guān)鍵點(diǎn)在于前后端的數(shù)據(jù)是如何傳遞的,理解了第一題我覺得第二題肯定也不會(huì)太難做,希望能夠幫到你。
????????????????????????????這是后端的servlet代碼,我寫的很簡(jiǎn)單,希望不要嫌棄。
????????????????????????
前端代碼: