Re: [ajax] (將code寫活的)要如何利用 javascript …

看板Ajax作者 (挺)時間16年前 (2009/11/05 16:13), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/2 (看更多)
這樣改寫還是失敗 無法船直到JSP 可是我改寫小程式 <%-- <%@page contentType="text/html" pageEncoding="UTF-8"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "" rel="nofollow">http://www.w3.org/TR/html4/loose.dtd"> <html> <script type = "text/javascript"> function sendRequest() { var url, qs; var name, passwd; xmlhttp = createXMLHttp(); if (xmlhttp) { passwd = aForm.passwd.value; name = "ee";//指派ee給name url = "test.jsp?"; qs = "account=" + name + "&passwd=" + passwd; //alert("url = " + url); xmlhttp.onreadystatechange = showMsg; xmlhttp.open("POST", url, true); // 非同步傳輸 + POST xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); xmlhttp.send(qs); //查詢字串 } } function createXMLHttp() { var xhr; try { xhr = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { xhr = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e1) { try { xhr = new XMLHttpRequest(); } catch (e2) { xhr = null; } } } return xhr; } function showMsg() { var strMsg; if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { strMsg = "<hr>已成功接收,伺服器的回傳結果是:<p>" + xmlhttp.responseText; document.getElementById("disp").innerHTML = strMsg; } } </script> <form id="aForm" action="test.jsp"> 帳號:<input name="account" size="20"><br> 密碼:<input name="passwd" type="password" size="10"><p> <input type="button" value="送出去" onClick="sendRequest()"> <input type="reset" value="這次不算"></p> <div id="disp"></div> </form> </html> 把 url = "test.jsp"; 改寫 url = "test?.jsp"; <%@ page contentType = "text/html; charset=big5" %> <% request.setCharacterEncoding("UTF-8"); String strName = request.getParameter("account"); // strName = new String(request.getParameter("account").getBytes("ISO-8859-1")); out.println("<h2>"); out.println(strName + ", 你好!<br>"); out.println("你的密碼是:"); out.println(request.getParameter("passwd")); out.println("</h2>"); %> 都能把javascript傳值(post) jsp 請問大家是哪邊出問題 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 210.240.197.182
文章代碼(AID): #1Ayeb76J (Ajax)
文章代碼(AID): #1Ayeb76J (Ajax)