javascript - how to include HTML form method=DELETE for the same "action" in the REST service call -


i want include delete method in same html form, calling same action(calling rest service) . how do ? . current html form looks :, delete functionality not work , post does. have included rest resource service well. suggestions appreciated.

  <!doctype html> <html>  <head>   <title>form create new resource</title>   <style>     tab { padding-left: 4em; }     </style>  </head> <body>   <form id= "myform" action="../com.dcr.jersey.first/rest/todos" >    <label for="id">id</label>   <input name="id" />   <br/>   <label for="summary">summary</label>   <input name="summary" />   <br/>   description:   <textarea name="description" cols=40 rows=6></textarea>   <br/>    <button type="submit" value="submit">submit</button>  <tab> <button type="submit" value="delete">delete</button>   <script>       $("button.submit").click(function(){             $("#myform").attr("method", "post");         });          $("button.delete").click(function(){             $("#myform").attr("method", "delete");         });   </script>  </form>  </body> </html>  

todosresource.java

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 resource url todos @path("/todos") public class todosresource {      // allows insert contextual objects class,       // e.g. servletcontext, request, response, uriinfo       @context       uriinfo uriinfo;       @context       request request;       @context       todo todo;     // return list of todos user in browser       @get       @produces(mediatype.text_xml)       public list<todo> gettodosbrowser() {         list<todo> todos = new arraylist<todo>();         todos.addall(tododao.instance.getmodel().values());         return todos;       }     // return list of todos applications       @get       @produces({ mediatype.application_xml, mediatype.application_json })       public list<todo> gettodos() {         list<todo> todos = new arraylist<todo>();         todos.addall(tododao.instance.getmodel().values());         return todos;       }     // retuns number of todos       // use http://localhost:8080/de.vogella.jersey.todo/rest/todos/count       // 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 " + id +  " not found");             else servletresponse.sendredirect("../create_todo.html");       }          @path("{todo}")       public todoresource gettodo(@pathparam("todo") string id) {             return new todoresource(uriinfo, request, id);       } } 

isn't property called "formmethod" , not method. method attribute @ form level. try $("#myform").attr("formmethod", "post"); instead


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -