public static String getStringFromAjaxSendData(HttpServletRequest request)
{
String result = "";
try
{
byte buffer[] = new byte[8192];
ServletInputStream stream = request.getInputStream();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
for (int bLen = 0; (bLen = stream .read(buffer)) > 0;)
baos.write(buffer, 0, bLen);
result = new String(baos.toByteArray(), "UTF-8");
System.out.println("utf-8:"+result );
}
catch (Exception e)
{
e.printStackTrace();
}
return result ;
}
xmlHttp.Open("POST",url,false);
xmlHttp.setRequestHeader("Content-Type","multipart/form-data");
xmlHttp.send(data);
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/15116811/viewspace-674777/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/15116811/viewspace-674777/
本文介绍了一种从Ajax发送的数据中获取字符串的方法,并展示了如何通过Java的Servlet读取这些数据。此外,还提供了使用XMLHttpRequest进行POST请求的具体代码示例。
7万+

被折叠的 条评论
为什么被折叠?



