title: how to include HTML form method=DELETE for the same "action" in the REST service call
body: <p>I want to include DELETE method in the same HTML form, calling the same action(calling a REST service) . How do I do this ? . My current HTML form looks like this :, the DELETE functionality does not work , but the POST does. I have included the REST resource service as well. Any suggestions is appreciated.</p>
  
  <pre><code>  &lt;!DOCTYPE html&gt;
  &lt;html&gt;
   &lt;head&gt;
    &lt;title&gt;Form to create a new resource&lt;/title&gt;
    &lt;style&gt;
      tab { padding-left: 4em; }
      &lt;/style&gt;
   &lt;/head&gt;
  &lt;body&gt;
  
   &lt;form id= "myForm" action="../com.dcr.jersey.first/rest/todos" &gt;
  
    &lt;label for="id"&gt;ID&lt;/label&gt;
    &lt;input name="id" /&gt;
    &lt;br/&gt;
    &lt;label for="summary"&gt;Summary&lt;/label&gt;
    &lt;input name="summary" /&gt;
    &lt;br/&gt;
    Description:
    &lt;TEXTAREA NAME="description" COLS=40 ROWS=6&gt;&lt;/TEXTAREA&gt;
    &lt;br/&gt; 
    &lt;button type="submit" value="Submit"&gt;Submit&lt;/button&gt;  &lt;tab&gt; &lt;button type="submit" value="Delete"&gt;Delete&lt;/button&gt;
    &lt;script&gt;
        $("button.Submit").click(function(){
              $("#myForm").attr("method", "POST");
          });
  
          $("button.delete").click(function(){
              $("#myForm").attr("method", "DELETE");
          });
    &lt;/script&gt;
  
  &lt;/form&gt;
  
  &lt;/body&gt;
  &lt;/html&gt; 
  </code></pre>
  
  <p>TodosResource.java</p>
  
  <pre><code>package com.dcr.jersey.jaxb.resources;
  
  import java.io.IOException;
  import java.util.ArrayList;
  import java.util.List;
  
  import javax.servlet.http.HttpServletResponse;
  import javax.ws.rs.Consumes;
  import javax.ws.rs.DELETE;
  import javax.ws.rs.FormParam;
  import javax.ws.rs.GET;
  import javax.ws.rs.POST;
  import javax.ws.rs.Path;
  import javax.ws.rs.PathParam;
  import javax.ws.rs.Produces;
  import javax.ws.rs.core.Context;
  import javax.ws.rs.core.MediaType;
  import javax.ws.rs.core.Request;
  import javax.ws.rs.core.UriInfo;
  
  import com.dcr.jersey.jaxb.dao.TodoDao;
  import com.dcr.jersey.jaxb.model.Todo;
  //Will map the resource to the URL todos
  @Path("/todos")
  public class TodosResource {
  
      // Allows to insert contextual objects into the class,
        // e.g. ServletContext, Request, Response, UriInfo
        @Context
        UriInfo uriInfo;
        @Context
        Request request;
        @Context
        Todo todo;
      // Return the list of todos to the user in the browser
        @GET
        @Produces(MediaType.TEXT_XML)
        public List&lt;Todo&gt; getTodosBrowser() {
          List&lt;Todo&gt; todos = new ArrayList&lt;Todo&gt;();
          todos.addAll(TodoDao.instance.getModel().values());
          return todos;
        }
      // Return the list of todos for applications
        @GET
        @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
        public List&lt;Todo&gt; getTodos() {
          List&lt;Todo&gt; todos = new ArrayList&lt;Todo&gt;();
          todos.addAll(TodoDao.instance.getModel().values());
          return todos;
        }
      // retuns the number of todos
        // Use http://localhost:8080/de.vogella.jersey.todo/rest/todos/count
        // to get the total number of records
        @GET
        @Path("count")
        @Produces(MediaType.TEXT_PLAIN)
        public String getCount() {
          int count = TodoDao.instance.getModel().size();
          return String.valueOf(count);
        }
  
        @POST
        @Produces(MediaType.TEXT_HTML)
        @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
        public void newTodo(@FormParam("id") String id,
            @FormParam("summary") String summary,
            @FormParam("description") String description,
            @Context HttpServletResponse servletResponse) throws IOException {
          Todo todo = new Todo(id, summary);
          if (description != null) {
            todo.setDescription(description);
          }
          TodoDao.instance.getModel().put(id, todo);
          servletResponse.sendRedirect("../Created_PopUp.html");
        }  
  
        @POST
        @Produces(MediaType.TEXT_HTML)
        @Consumes({MediaType.APPLICATION_XML,MediaType.APPLICATION_JSON})
  
        public void newTodoXMLJSON(Todo todo) throws IOException {
          this.todo=todo;
          TodoDao.instance.getModel().put(todo.getId(), todo);
        }  
  
        @DELETE
        @Produces(MediaType.TEXT_HTML)
        @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
        public void delTodo(@FormParam("id") String id,
            @Context HttpServletResponse servletResponse) throws IOException {
            Todo c = TodoDao.instance.getModel().remove(id);
              if(c==null)
                throw new RuntimeException("Delete: Todo with " + id +  " not found");
              else servletResponse.sendRedirect("../create_todo.html");
        }  
  
        @Path("{todo}")
        public TodoResource getTodo(@PathParam("todo") String id) {
              return new TodoResource(uriInfo, request, id);
        }
  }
  </code></pre>