Home > Back-end >  Ajax upload files, backend servlet using getParameter receive to NULL
Ajax upload files, backend servlet using getParameter receive to NULL

Time:09-21

I wrote on the front end of a file upload songs id and songs ajax, backend servlet using getparameter receiving, but receives the value is NULL, the front-end and back-end played a breakpoint, front end can be normal to get songs file and song id, but can be normal to enter the servlet servlet in the value of the empty, I put the song files to delete the parameter, the only one song id, song in the background can be normal to get id, don't understand, ask bosses solutions,
This is ajax code
This is see normal to get the data in the Google browser
This is the background the servlet code

CodePudding user response:

Ajax upload files because you may not be normal access to the header information is different and you can upload files? First, you can understand the form to upload file
You know how to get the file servlet
 var formData=https://bbs.csdn.net/topics/new formData (); 
Var temp=$(" # filexx "). The get (0) files [0].//& lt; Input the id="filexx" type="file" & gt;
Var filenamex="../img/type1_ "+ parseInt ((Math) random () * 1000 + 10)) + temp. The name;
FormData. Append (" file ", temp, filenamex);//upload a object files
$. Ajax ({
Url: "PritureSe? Type=",
1Data: formData,
Type: "POST",
Cache: false,
ContentType: false,
ProcessData: false,
Success: the function (data) {

});
}
});

The servlet file can use Commons fileupload - Commons - IO or anything else

CodePudding user response:

Using formdata upload file, I don't know your that img. Substr (1) what is,
Var formData=https://bbs.csdn.net/topics/new formData ();
FormData. Append (" file ", the file).
Use this way to upload files, generally before uploading to determine the file format, the back-end using MultipartFile receive it is ok, the hope can help you

CodePudding user response:

Not all browsers support formdata, or use the form + iframe insurance,

CodePudding user response:

DataType: "json"

CodePudding user response:

Possible pictures too big

Reference & gt;> Post method to upload base64 encoded images to the backend to null

CodePudding user response:

I also encountered similar problems, but I am using formdate, this is the data in the form of form data upload together, if the file background MultipartFile, with MultipartFile can only accept documents, formdate except file values can be received directly, MultipartFile accept files can be baidu way,
  • Related