Announcement Announcement Module
No announcement yet.
urgent: send a jquery ajax request which sends a byte[] to the controller .. Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • urgent: send a jquery ajax request which sends a byte[] to the controller ..

    Hi I want to send a byte[] to the controller and create a string back from that byte[] .
    By default spring's httpbytearrayconverter incorrectly converts the byte[] ( when i send a byte[] of size 100 , on server side spring create a byte[] size of 1800 nearly )

    my ajax sample which sends some byte[] to the spring controller looks like this :

    var byteArray = utf8.toByteArray(data);
    type : 'POST',
    url : "/userloglevel/logreport/",
    data : byteArray,
    success : function(data) {

    controller method :

    @RequestMapping(value = "/", method = RequestMethod.POST)

    public @ResponseBody

    String logReport(@RequestParam("byteArray") byte[] data) {

    try {

    //String input = new String(data);

    but spring is giving the error like there is no parameter called byteArray in the request ..

    I want to know the correct method signature and what are the dependencies requered for this to work correctly , otherwise any working sample would help..?

    Thanks for your help !!

  • #2
    Also when i declare the method as

    String logReport(@RequestBody("byteArray") byte[] data) {
    it incorrectly gives the data back

    Please let me know how to declare the method signature inorder to get the exact byte[] that i send from client



    • #3
      Have you considered the new multipart support in Spring 3.1?

      For example:
      @RequestMapping(value="/someUrl", method = RequestMethod.POST)
      public String onSubmit(@RequestPart("meta-data") MetaData metadata,
                             @RequestPart("file-data") MultipartFile file) {
          // ...
      See for more info.


      • #4
        Thanks for your reply.

        Is there any way that we can do this functionality in spring 3.0.5 , because now i am not in a position to upgrade to 3.1