Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

163
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda