my html code:
<input type="file" id="myFile" name="files[]">
ajax code:
var file = document.getElementById('myFile').files[0].name;
var poststr = 'file='+ escape(file)+'&key='+ escape('project_creation');
makePOSTRequest('controller', poststr,'bdy');
Controller:
if (param.equals("project_creation")) {
param="project_creation";
int proj_id = hlp.createProject(req,emp_id);
}
通过请求检索时,我只获取文件名。我需要将文件保存在本地路径中。
任何帮助将不胜感激。提前致谢。
最佳答案
你用过Form吗?因此,不要忘记将属性 enctype="multipart/form-data"
添加到表单元素中。
关于java - 如何通过makePostRequest()中的ajax调用发送文件并通过 Controller 中的请求参数获取它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44542386/