您的位置:首页 > Web前端 > JavaScript

jsp下载服务器文件

2018-03-16 13:44 204 查看
1.java后端:保存待下载文件test.txt到realPath下面,其中:
String realPath = request.getSession().getServletContext().getRealPath("/");  
2.jsp端Java脚本:取项目访问路径basePath ,其中
<%
String contextPath = request.getContextPath();  
String basePath = request.getScheme()+"://"+request.getServerName()+":"+ request.getServerPort()+contextPath+"/";
%>
3.html标签中定义<input id="outputpath" type="hidden" value="<%=basePath %>"/>
4.js端:访问待下载资源window.location.href=document.getElementById("outputpath").value+"/test.txt";
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Java