jquery - Submit a handsontable to a spring mvc3 controller - Content type 'application/x-www-form-urlencoded' not supported -


im new spring mvc3 , looking @ jquery handsontable example.

here part of jsp page includes form

  <form:form action="${pagecontext.request.contextpath}/app/${application.id}/user/bulkimport" method="post">            <div id="datatable"></div>         <script>             var data = [                 ["156428", "admin,scc,superuser"],                 ["839302", "scc"]             ];             $("#datatable").handsontable({                 data: data,                 startrows: 3,                 startcols: 2             }); </script>       <script>    function submitentries(){         alert("in");             var tabledata = $("#datatable").handsontable("getdata");             var formdatajson = json.stringify({"data":tabledata});              jquery.ajax({                 url: 'bulkimport',                 type: 'post',                 contenttype: 'application/json; charset=utf-8',                 data: formdatajson,                 'success': function (e) {                     var resultstring = 'saved';                     $('#serverresults').html(resultstring);                 }             });    }     </script> 

controller:

@requestmapping(value="/bulkimport", method = requestmethod.post)     public string importusers(@requestbody bulkuserimportentries entries)             throws exception {          iterator itr = entries.getdata().iterator();         while(itr.hasnext()) {             object obj = (object)itr.next();         }          return "redirect:/app/{appid}/user/{id}";     } 

bulkuserimportentries class:

public class bulkuserimportentries implements serializable{        private list<object[]> data;        protected bulkuserimportentries() {}       protected bulkuserimportentries(list<object[]> data) {             this.data = data;       }        public list<object[]> getdata() {             return data;       } } 

im getting error when submitting form.

content type 'application/x-www-form-urlencoded' not supported

i recieve array of values jsp able iterate on controller. see possible on example using modelattribute . again im pretty new , have been stuck here week :(

thanks help

the problem when use application/x-www-form-urlencoded, spring doesn't understand requestbody. so, if want use must remove @requestbody annotation.

then try following:

@requestmapping(value="/bulkimport", method = requestmethod.post, consumes = mediatype.application_form_urlencoded_value) public string importusers(bulkuserimportentries entries) throws exception {      iterator itr = entries.getdata().iterator();     while(itr.hasnext()) {         object obj = (object)itr.next();     }      return "redirect:/app/{appid}/user/{id}"; } 

note removed annotation @requestbody , add consumes = mediatype.application_form_urlencoded_value

answer: http post request content type application/x-www-form-urlencoded not working in spring


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -