请教JSP高手:如何在JSP中实现下载功能 你这种方式只能用在本地!客户端是无法使用的,因为他会找客户机F:/web/src/jspSmartUpload.zip的文件,当然会找不到,要用服务器路径!即http://,或相对于当前页面的路径,前提是你指定的路径有此文件,就可以访问! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我用了相对路径后,仍然无法下载,还是显示无法打开该站点。Help me! <p><a href="jspSmartUpload.zip">dsfdasfaf</a></p>就是这样写的,有什么问题啊? 绝对路径,我也试过了,还是有问题<p><a href="http://182.168.1.1:8001/jspSmartUpload.zip">dsfdasfaf</a></p>index.htm页面和下载文件jspSmartUpload.zip在同一个目录下。 ● 软件下载问题 --------------------------------------------------------------- 例如此文件名是getfile.jsp 与此文件的同目录下有一个test.doc的word目录,则用 http://localhost/getfile.jsp?file=test.doc <%@page import="java.util.*"%> <%@page import="java.io.*"%> <%@page import="java.net.*"%> <% String filename = ""; if (request.getParameter("file") != null) { filename = request.getParameter("file"); } response.setContentType("application/msword"); response.setHeader("Content-disposition","attachment; filename="+filename); BufferedInputStream bis = null; BufferedOutputStream bos = null; try { bis = new BufferedInputStream(new FileInputStream(getServletContext().getRealPath("" + filename))); bos = new BufferedOutputStream(response.getOutputStream()); byte[] buff = new byte[2048]; int bytesRead; while(-1 != (bytesRead = bis.read(buff, 0, buff.length))) { bos.write(buff,0,bytesRead); } } catch(final IOException e) { System.out.println ( "³öÏÖIOException." + e ); } finally { if (bis != null) bis.close(); if (bos != null) bos.close(); } //return; %> java 实现jsp页面表格数据导入到Excel jsp页面出NullPointerException 怎么获取checkbox的多个值,并写入数据库的一个字段中 jsp如何动态生成html文件 請問myeclipse無法連接數據庫,到底是什麼回事呢? 关于页面信息传递的问题 高手来啊 利用POI做成Excel表格后,如果直接在浏览器里面打开 JBuilder编辑JSP问题 中文插入数据库是正常的,但从数据库中读出来后显示则成了乱码!!急,就这么点分了 在按钮的onclick="",怎么调用<%!%>里面申明的函数?? JSP环境配置大问题 程序不稳定?
就是这样写的,有什么问题啊?
<p><a href="http://182.168.1.1:8001/jspSmartUpload.zip">dsfdasfaf</a></p>
index.htm页面和下载文件jspSmartUpload.zip在同一个目录下。
例如此文件名是getfile.jsp
与此文件的同目录下有一个test.doc的word目录,则用
http://localhost/getfile.jsp?file=test.doc <%@page import="java.util.*"%>
<%@page import="java.io.*"%>
<%@page import="java.net.*"%>
<%
String filename = "";
if (request.getParameter("file") != null) {
filename = request.getParameter("file");
}
response.setContentType("application/msword");
response.setHeader("Content-disposition","attachment; filename="+filename);
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
try {
bis = new BufferedInputStream(new FileInputStream(getServletContext().getRealPath("" + filename)));
bos = new BufferedOutputStream(response.getOutputStream());
byte[] buff = new byte[2048];
int bytesRead;
while(-1 != (bytesRead = bis.read(buff, 0, buff.length))) {
bos.write(buff,0,bytesRead);
}
} catch(final IOException e) {
System.out.println ( "³öÏÖIOException." + e );
} finally {
if (bis != null)
bis.close();
if (bos != null)
bos.close();
}
//return;
%>