Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

162
Views
Which type is considered to be a FormData when handled from ajax.post to java through struts 2?

I haven´t found any answer in the forum, however it's possible the question has yet been asked. Sorry in advance, if that's the case.
Basically, I'm creating a FormData object in a jsp to capture an uploaded file and I would like to access it in my java Dispatcher. I tried the type FormData in java, but it looks like it doesnt exist.
Any help would be appreciated.
Here is the .jsp code:

var file_data = $("#fileUpload").prop("files")[0];   
   var file_name = $("#fileUpload").val();
   var form_data = new FormData();                  
   form_data.append("file", file_data);              
   form_data.append("fileName", file_name);  

       $.post('crearNuevaActa.action',
    {
    processData: false, 
    contentType: false,
    data: form_data,
    }
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

First convert your formData to JSON

var myFormData = JSON.stringify(form_data);

on your jQuery post change data to:

data:  "data:"+data,

On your action class include following,

private List<MyBean> data;

//setter and getter

Define MyBean POJO class;

class MyBean{
//include  file filename and any other field you have 
//getter setter
}

configure your action class to deserialize JSON

<action name="" class="">
    <result type="json"/>
  <interceptor-ref name="json">
  <interceptor-ref name="defaultStack">
</action>
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!