nalin
07-02-2009, 09:09 PM
Hi My client code is trying to communicate with a servlet and sending data in json format.
Client code :
var myJSONObject = {"name":"hello","address":"xyz"};
var toServer = myJSONObject.toJSONString();
var request=new XMLHttpRequest();
request.open("POST", "http://localhost:8080/User/UserRegistration", true);
request.send(toServer);
return true;
}
catch(err)
{
alert(err.message);
}
}
Servlet Code :
public class UserRegistration extends HttpServlet {
@Override
public void doGet(
HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
PrintWriter out = response.getWriter();
String output = request.getParameter("toServer");
System.out.println(output);}}
The data recieved at the servlet is always null..Can someone explain me the reason behind this?
Client code :
var myJSONObject = {"name":"hello","address":"xyz"};
var toServer = myJSONObject.toJSONString();
var request=new XMLHttpRequest();
request.open("POST", "http://localhost:8080/User/UserRegistration", true);
request.send(toServer);
return true;
}
catch(err)
{
alert(err.message);
}
}
Servlet Code :
public class UserRegistration extends HttpServlet {
@Override
public void doGet(
HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
PrintWriter out = response.getWriter();
String output = request.getParameter("toServer");
System.out.println(output);}}
The data recieved at the servlet is always null..Can someone explain me the reason behind this?