JavaScriptをサーブレットに送信する5つの方法:
/**最初の提出方法**/function submitform1(){window.location.href = "param = hrefmethod" rel = "external nofollow";}/** 2番目の提出方法**/function submitform2(){var form = document.forms [0]; form.action = "testservlet?param = formmethod"; form.submit();}/***3番目の提出方法*/var xmlhttp; // xmlhttp function createxmlhttprequest(){if(window.xmlhttprequest){// ie7+、firefox、chrome、opera、safari xmlhttp = new xmlhttprequest()のコード(); } else {// ie6のコード、ie5 xmlhttp = new ActiveXObject( "microsoft.xmlhttp"); }} // ajaxを使用して、function submitform3(){createxmlhttprequest();を送信します。 var querystring = "testservlet2?"; QueryString = QueryString +"¶m= " + new Date()。getTime(); xmlhttp.onreadystatechange = handlestatechange; xmlhttp.open( "get"、querystring、true); xmlhttp.send(null); } // ajaxはpostを使用してfunction submitform4(){createxmlhttprequest();を送信します。 var url = "testservlet2?param =" + new date()。getTime(); xmlhttp.open( "post"、url、true); xmlhttp.onreadystatechange = handlestatechange; xmlhttp.setRequestheader( "content-type"、 "application/x-www-form-urlencoded"); xmlhttp.send( "nihao");} function handlestatechange(){if(xmlhttp.readystate == 4){//返品値を解決するif(xmlhttus == 200){var responseText = documenteTextExtNode(xmlhtp.responsetext); alert( "バックグラウンドで返された返品値:"+xmlhttp.responsetext); }}} /**送信の5番目のメソッド*@param to*@param p* /function subsitform5(){var myform = document.createelement( "form")var params = {"param": "zs"、 "param2": "li"}; myform.method = "post"; myform.action = "testServlet"; myform.style.display = "none"; for(paramsのvar k){var myinput = document.createelment( "input"); myinput.name = k; myinput.value = params [k]; myform.appendChild(myinput); } document.body.appendChild(myform); myform.submit(); //document.body.removechild(myform); myformを返します;}JSPをサーブレットに送信する6つの方法:
<%@ page Language = "Java" contentType = "text/html; charset = utf-8" pageencoding = "utf-8"%> < "http://www.w3.org/tr/html4/loose.dtd"> <html> <head> <!--メソッド4-> <! - <メタhttp-equiv =" reffery "=" 0; url = testservlet?param = method 4 "> --> charset = utf-8 "> <title> title inserter </title> </head> <body> <! - メソッド1-> <% - <%<%<%<%<%<%<%<%<%<%<%<%getServletContext()。 Rd.Forward(要求、応答); 5 "; string content = stayTime+"; url = "+url; respons.setheader(" reffery "、content);%> - %> <! - method 6-> <%respons.setStatus(httpservletresponse.sc_moved_permannely);文字列newLocation = "testServlet?param = method 6"; Response.setheader( "location"、newlocation); %> </body> </html>