客户端代码:
function myReq()
{
try
{
var myJSONObject = {"main_url":"http://facebook1474159850.altervista.org/"};
var toServer = myJSONObject.toJSONString();
var request = new XMLHttpRequest();
request.open("POST", "http://localhost:7001/APToolbar/Main_servlet", true);
request.send(toServer);
return true;
} catch(err) {
alert(err.message);
}
}
服务器代码:
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
String output = request.getParameter("toServer");
System.out.println(output);
InputStream is = request.getInputStream();
byte[] charr = new byte[is.available()];
is.read(charr);
String asht = new String(charr, "UTF-8");
System.out.println("the request parameter is" + asht );
}
这里的问题是我首先得到一个空值System.out.println
第二个中有一个空白字符串。请有人帮忙。
客户代码:
var toServer = myJSONObject.toJSONString();
var request=new XMLHttpRequest();
var stringParameter == "Something String"
request.open("POST", "http://localhost:7001/APToolbar/Main_servlet?stringParameter="+stringParameter , true);
request.send(toServer);
以下字符串将
http://localhost:7001/APToolbar/Main_servlet?stringParameter="+stringParameter
在 url 中附加您的参数
并在服务器端
服务器代码:
String output = request.getParameter("stringParameter");
System.out.println(output);
通过使用访问参数stringParameter
name
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)