Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8463037
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T14:21:16+00:00 2026-06-10T14:21:16+00:00

I am trying to pass array of files object to spring MVC controller. But

  • 0

I am trying to pass array of files object to spring MVC controller. But I am getting 400 Bad request error.

In my jsp I have written a jquery method to get the array of files.

function getFilelist() {
      var files = $('body').data('filelist');
      return files;
}

And uploading these all files using post Json method.

—Updated—-

I am adding the whole init() method:

function init() {
    $('input:button').button();
    $('#submit').button();

    $('#uploadForm').submit(function(event) {
        event.preventDefault();   

        alert("uploading..");

        $.postJSON('fileSave.htm', {
            filename: getFilelist()    
        },
                   function(result) {
                       if (result.success == true) {
                           dialog('Success', 'Files have been uploaded!');
                       } else {
                           dialog('Failure', 'Unable to upload files!');
                       }
                   });
    });

    $('#reset').click(function() {
        clearForm();
        dialog('Success', 'Fields have been cleared!');
    });

    $('#upload').fileupload({
        dataType: 'json',
        done: function (e, data) {
            $.each(data.result, function (index, file) {
                $('body').data('filelist').push(file);
                $('#filename').append(formatFileDisplay(file));
                $('#attach').empty().append('Add another file');
            });
        }
    });

    $("#attach").click(function () {
        $("#upload").trigger('click');
    });

    $('body').data('filelist', new Array());
}

Here getFilelist() is the array of file objects. In my controller I have written:

@RequestMapping(value="fileSave", method=RequestMethod.POST)
public @ResponseBody StatusResponse message(
    @RequestParam("filesAttachedList") FilesAttachedList filesAttachedList) {
  // some code here
}

My FilesAttachedList class:

public class FilesAttachedList implements Serializable {
    private static final long serialVersionUID = 5944305104394883501L;
    private List<FileAttachment> filesList;

    public List<FileAttachment> getFilesList() {
        return filesList;
    }

    public void setFilesList(List<FileAttachment> filesList) {
        this.filesList = filesList;
    }

    @Override
    public String toString() {
        return "FilesAttachedList [filesList=" + filesList + "]";
    }
}

So how can I pass the array of objects from jquery to controller?

–updated–

When I check the browser getFileList returns

 Object
 attachableId: null
 attachableType: null
 attachmentContentType: null
 attachmentFileName: "http://localhost:8080/myproject/resources/images.jpg"
 attachmentFileSize: 6994
 attachmentUpdatedAt: null
 createdAt: null
 creatorId: null
 id: null
 name: "images.jpg"
 updatedAt: null
 updaterId: null
 __proto__: Object
 length: 1
 __proto__: Array[0]

This is what if I add two image objects

 Array[2]
 0: Object
 1: Object
 length: 2
 __proto__: Array[0]

—-Update 3 —

when I change from @RequestParam("filesAttachedList") FilesAttachedList filesAttachedList to @RequestBody final String filesAttachedList and add two images it gives me the following string objects. Can I read this string?

{
  "filename": [
    {
      "id": null,
      "createdAt": null,
      "updatedAt": null,
      "name": "images.jpg",
      "attachableId": null,
      "attachableType": null,
      "attachmentFileName": "http:\/\/localhost:8080\/myproject\/resources\/images.jpg",
      "attachmentContentType": null,
      "attachmentFileSize": 6994,
      "attachmentUpdatedAt": null,
      "creatorId": null,
      "updaterId": null
    },
    {
      "id": null,
      "createdAt": null,
      "updatedAt": null,
      "name": "lion.jpg",
      "attachableId": null,
      "attachableType": null,
      "attachmentFileName": "http:\/\/localhost:8080\/myproject\/resources\/lion.jpg",
      "attachmentContentType": null,
      "attachmentFileSize": 36670,
      "attachmentUpdatedAt": null,
      "creatorId": null,
      "updaterId": null
    }
  ]
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T14:21:17+00:00Added an answer on June 10, 2026 at 2:21 pm

    You didn’t print {, }, [ and ] characters which are important here, but I assume it’s just one Object while your controller expects a list of FileAttachment objects.

    Either add surround files in JS with array return [ files ]; or, if it’ll always be only on FileAttachment change controller to @RequestParam("fileAttachment") FileAttachment fileAttachment.

    EDIT:

    Can you change @RequestParam("fileAttachment") to @RequestParam("filename")? I see you edited your question meanwhile.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to pass an array in an ajax request, but apparently it doesn't
I am trying to pass an array of a simple object to a web
I am trying to pass array parameter to SQL commnd in C# like below,
I am trying to pass a array that contains keys and values. The keys
I'm trying to pass an array to my template with a simple tag. I
I am trying to pass an array (2d) to a function as an parameter.
1.I was trying to pass an array of string from 1 activity to another
I am currently trying to pass an array that I have created in Javascript
I'm having a problem when trying to pass an array back to a COM
I'm trying to pass this associative array to JavaScript: Array ( [0] => Array

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.