ajax+jsp send a large string string code

Source: Internet
Author: User
Tags stringbuffer

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 ());
}
}
%>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.