0
我有一个Tapestry Web应用程序。 要实现一个支持Ajax文件上传,我使用如下所示的简单的JavaScript(我已经评估现有的Tapestry对Ajax的上传的解决方案,但不能让他们的工作):Ajax文件上传在挂毯5.4
var fileSelect = document.getElementById('file-select');
var files = fileSelect.files;
var formData = new FormData();
var file = files[0];
formData.append("file", file, file.name);
var xmlhttp;
if (window.XMLHttpRequest) {
xmlhttp=new XMLHttpRequest();
} else {// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
console.log(xmlhttp.responseText);
}
}
xmlhttp.open("POST", "FileUpload",true);
xmlhttp.send(formData);
}
而在的FileUpload页,我有:
@Inject
private Request request;
public Object onActivate() {
String fileName = request.getParameter("file");
String path = "c:\\tapestry_temp";
File file = new File(path, fileName);
if (file.exists()) {
System.out.println("File found");
} else {
System.out.println("File not found");
}
}
....
现在,当我上传文件时,JavaScript是没有问题的执行,并在的FileUpload页面中,文件名具有正确的价值(NAM e的上传文件),但我不知道如何访问上传的文件?它存储在哪里?
PS:在的AppModule(ContributeApplicationDefaults),我有事先
configuration.add(UploadSymbols.REPOSITORY_LOCATION,"c:\\tapestry_temp");
感谢。