0

I am a beginner, trying to implement a simple CRUD application using jersey. I am trying to delete one row based on the input passed by the user through a web page. But my method is not being called i am getting the following error.

HTTP Status 405 - Method Not Allowed

type Status report

message Method Not Allowed

description The specified HTTP method is not allowed for the requested resource.

This following is my delete function which should delete based on the FormParam it gets through html.

      @DELETE
      @Path("/delete")
      @Produces(MediaType.TEXT_HTML)
      public void delEmployeeFormParam(@FormParam("Employee_id") int employee_id){

            java.net.URI location= null;
            System.out.println("teting");
            try 
            {
                Class.forName("com.mysql.jdbc.Driver");
                Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/Employee_db", "root", "root");

                String query = "delete from employee where emp_id = (?)";

                PreparedStatement st = con.prepareStatement(query);
                st.setInt(1, employee_id);
                st.executeQuery();

            } 
            catch (Exception e) 
            {
                System.out.println(e.getMessage());
            }

      }

The html code is shown below.

<body>
    <h3> Enter Employee Id to Delete </h3>

    <div>
        <form method="DELETE" action="http://localhost:8080/RESTCRUD/rest/employee/delete">
            <p>Employee Id: <input type:"text" name="Employee_id"/></p>
            <input type="submit" value="submit"/>
        </form>
    </div>

</body>

One thing to Note other methods such as GET and POST are working fine.

kiran6
  • 1,247
  • 2
  • 13
  • 19

1 Answers1

0

I don't think HTML forms support DELETE (only GET and POST). See this question here for more details.

HTML forms (up to HTML version 4 and XHTML 1) only support GET and POST as HTTP request methods.

Community
  • 1
  • 1
Pace
  • 41,875
  • 13
  • 113
  • 156
  • For debugging you can do a couple of things. You can use a command line tool like `curl` or a browser REST API calling extension to test out the DELETE and confirm the server is configured correctly. You could also attach a proxy or log the request parameters to see what is really getting passed by the browser. – Pace May 11 '16 at 00:30