I have developer a Java Servlet that works well with application/javascript requests such as:
curl -H "application/javascript" -X POST -d "action=register_user" http://example.com/api/users
I want it to accept application/json as well, because in the request below the servlet cannot detect any parameters
curl -H "Content-Type: application/json" -X POST -d '{"action":"register_user"}' http://example.com/api/users
How can I modify the servlet below to make it work with application/json?
public class Manage extends HttpServlet {
/**
* @see HttpServlet#HttpServlet()
*/
public Manage() {
}
public Manage(Server server) {
super();
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
@SuppressWarnings("unchecked")
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String action = request.getParameter("action");
dosomething(action);
}