1

How to send multiple parametrs in HTTP POST request? I am sending POST request through Ajax call to servlet I tried below two ways but neither worked

Approach 1:

httpRequest.open("POST", "http://localhost/Servlet/ps" , true);
httpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
.
.
.
httpRequest.send("msg="+data & "TC="+TC);

At Servlet:

String data = req.getParameter("msg"); // this prints value fine

String TestCaseNo = req.getParameter("TC"); // this prints null

Approach 2:

httpRequest.open("POST", "http://localhost/Servlet/ps" , true);
httpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
.
.
.
httpRequest.send("msg="+data + "TC="+TC);

ANSWER:This is how it worked for me

var value="msg="+data+"&TC="+TC;
http-Request.send(value);
user3712016
  • 203
  • 3
  • 6
  • 16

1 Answers1

0

I'm unfamiliar with AJAX but this seems more like a setup for GET request httpRequest.send("msg="+data & "TC="+TC). Try writing parameters to your connection output stream and then in doPost method get it from req.getInputStream(). This will definitely work, but idk if it's exactly what your asking for.