ajax+jsp Tutorial Send large string string code
<%@ page language= "java" import= "java.util.*" pageencoding= "UTF-8"%>
<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" >
<title> Send large string string </title>
<body>
<input type= "button" value= "Send" onclick= "Send ();" />
</body>
<script type= "Text/javascript Tutorial" >
var xmlHttp = null;
function Createxmlhttprequest () {
if (window. ActiveXObject) {
XmlHttp = new ActiveXObject ("Microsoft.XMLHTTP");
}else if (window.xmlhttprequest) {
XmlHttp = new XMLHttpRequest ();
}
}
var bigstr = "$";
for (Var i=0;i<500;i++) {
Format: keyi$valuei$
Bigstr + + "key" +i+ "$value" +i+ "$";
}
function Send () {
Createxmlhttprequest ();
Xmlhttp.onreadystatechange = process;
Xmlhttp.open ("POST", "Testgetbigstr", true);
Xmlhttp.setrequestheader ("Content-type", "application/x-www-form-urlencoded");
Xmlhttp.send (BIGSTR);
}
function process () {
if (xmlhttp.readystate==4) {
if (xmlhttp.status==200) {
Alert ("Send success!") ");
}
}
}
</script>
<%
Servlet Code:
Package com.test;
Import Java.io.BufferedReader;
Import java.io.IOException;
Import Java.io.PrintWriter;
Import javax.servlet.ServletException;
Import Javax.servlet.http.HttpServlet;
Import Javax.servlet.http.HttpServletRequest;
Import Javax.servlet.http.HttpServletResponse;
public class Testgetbigstr extends HttpServlet {
public void doget (HttpServletRequest request, httpservletresponse response)
Throws Servletexception, IOException {
DoPost (Request,response);
}
public void DoPost (HttpServletRequest request, httpservletresponse response)
Throws Servletexception, IOException {
StringBuffer sb = new StringBuffer ();
BufferedReader br = new BufferedReader (Request.getreader ());
String line= "";
while ((Line=br.readline ())!=null) {
Sb.append (line);
}
System.out.println (Sb.tostring ());
}
}
%>