从使用Ajax的Servlet下载文件
我已经创建了我的servlet的zip文件。现在我想使用Ajax来触发这个servlet并提示下载对话框的用户。我可以触发这个servlet,但我不知道怎么去保存对话框。我怎样才能做到这一点?
I have created a zip file in my servlet. Now I would like to trigger that servlet using Ajax and prompt the download dialog to the user. I can trigger the servlet, but I don't know how to get the save dialog. How can I achieve this?
您无法下载使用AJAX的文件。 AJAX是有关从服务器的JavaScript处理下载数据。
You can't "download a file using AJAX". AJAX is about downloading data from a server for JavaScript to process.
要允许用户下载该文件或者使用一个简单的链接到文件/ servlet或如果你真的,真的需要使用JavaScript,然后将URL分配给 document.location.href
。
To let the user download the file either use a simple link to the file/servlet, or if you really, really need to use JavaScript, then assign the URL to document.location.href
.
另外,你需要确保服务器(或在这种情况下,该servlet)发送相应的MIME类型,情况最有可能的一个ZIP文件的应用程序/压缩
Also you need to make sure that the server (or in this case the servlet) sends the appropriate MIME type, in case of a ZIP file most likely application/zip
.