<分区>
我在我的 Tomcat 文件夹中保存了一个文本文件, c:\program files/apache software foundation/tomcat7.0/test/test.txt
我只能在自己电脑的浏览器中打开。
如何下载并保存到我的本地磁盘,例如:f:\test.txt。
我可以只使用 Javascript 吗? 有示例代码吗?
感谢一百万!
<分区>
我在我的 Tomcat 文件夹中保存了一个文本文件, c:\program files/apache software foundation/tomcat7.0/test/test.txt
我只能在自己电脑的浏览器中打开。
如何下载并保存到我的本地磁盘,例如:f:\test.txt。
我可以只使用 Javascript 吗? 有示例代码吗?
感谢一百万!
最佳答案
所有网络服务器都支持ajax。您只能从本地网络服务器尝试 ajax。要上传到服务器,您需要购买域名和空间。联系任何网络托管公司,他们会为您提供指导,例如:http://godaddy.com/ .下面是从服务器读取文本文件的 ajax 代码
var txtFile = new XMLHttpRequest();
txtFile.open("GET", "http://www.example.com/data/data.txt", true);
txtFile.onreadystatechange = function() {
if (txtFile.readyState === 4) { // Makes sure the document is ready to parse.
if (txtFile.status === 200) { // Makes sure it's found the file.
allText = txtFile.responseText;
lines = txtFile.responseText.split("\n"); // Will separate each line into an array
}
}
}
txtFile.send(null);
关于javascript - 如何通过javascript从tomcat服务器下载文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17544036/
相关文章:
javascript - 在 php 中向输入类型图像添加 Click 函数,出现未定义错误
java - 是否可以在 tomcat 中的过滤器的 doFilter 函数中恢复 Referrer?
eclipse - 从外部 jar 到 maven 的项目转换失败
javascript - 在 AngularJS 中使用窗口访问 iframe 内容
javascript - 如何在javascript中计算对象中的子对象?
javascript - react Hook : fetch data inside useEffect warning