title: Java Servlet return error 405 (Method Not Allowed) for POST request
body: <p>My servet work fine for get requests but when I call POST (using jquery ajax $.post) I get error 405 (Method Not Allowed) </p>
  
  <p>Here is my code:</p>
  
  <pre><code>import java.io.*;
  import javax.servlet.*;
  import javax.servlet.http.*;
  
  public class init extends HttpServlet {
      public init() { }
      public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
          response.setContentType("text/plain");
          PrintWriter out = response.getWriter();
          out.println("GET");
      }
      public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, IllegalStateException {
          response.setContentType("application/json");
          ServletInputStream in = request.getInputStream();
          PrintWriter out = response.getWriter();
          out.print("POST");
      }
  }
  </code></pre>