Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
27
rated 0 times [  34] [ 7]  / answers: 1 / hits: 23936  / 11 Years ago, tue, march 12, 2013, 12:00:00

Client code :



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


Server code:



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


Problem here is i am getting a null value in first System.out.println and a blank string in second one. Please somebody help.


More From » java

 Answers
96

Client Code :



 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);


following string will



http://localhost:7001/APToolbar/Main_servlet?stringParameter=+stringParameter


append your parameter in url



and at server side



Server code :



String output = request.getParameter(stringParameter);
System.out.println(output);


access parameter by using stringParameter name


[#79653] Monday, March 11, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
payne

Total Points: 527
Total Questions: 108
Total Answers: 88

Location: Tajikistan
Member since Thu, Apr 14, 2022
2 Years ago
payne questions
Thu, Sep 3, 20, 00:00, 4 Years ago
Tue, Aug 18, 20, 00:00, 4 Years ago
Thu, Oct 11, 18, 00:00, 6 Years ago
;