see
Send Files to Browser Clients the Right Way
http://www.fawcette.com/javapro/2002_03/online/online_eprods/servlets_03_08/use
response.setContentType("APPLICATION/OCTET-STREAM");
response.setHeader("Content-Disposition","attachment; filename=\""
+ filename + "\"");in your html, try something like
<td><a href="servletName?file=file.txt" target="_blank">file</a></td>
Send Files to Browser Clients the Right Way
http://www.fawcette.com/javapro/2002_03/online/online_eprods/servlets_03_08/use
response.setContentType("APPLICATION/OCTET-STREAM");
response.setHeader("Content-Disposition","attachment; filename=\""
+ filename + "\"");in your html, try something like
<td><a href="servletName?file=file.txt" target="_blank">file</a></td>
http://www.csdn.net/Develop/read_article.asp?id=13004
明天再帖一个具体的
<%
'Forcing an image to download using the ADO Stream Object
response.contenttype="application/x-unknown"
response.addheader "Content-Disposition","attachment; filename=" & chr(34) & "logo.gif" & chr(34)response.binarywrite getBinaryFile(server.mappath("logo.gif"))function getBinaryFile(fileSpec)
Dim adTypeBinary
adTypeBinary = 1
Dim oStream
set oStream = server.createobject("ADODB.Stream")
oStream.Open
oStream.Type = adTypeBinary
oStream.LoadFromFile fileSpec
getBinaryFile= oStream.read
set oStream=nothing
end function
%>
try{
FileOutputStream fos = new FileOutputStream(outputFileName);
CheckedOutputStream cos = new CheckedOutputStream(fos, new Adler32());
ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(cos));
File inputFile = new File(inputFileName);
FileInputStream fis = new FileInputStream(inputFile);
BufferedInputStream bis = new BufferedInputStream(fis, BUFFER);
ZipEntry entry = new ZipEntry(inputFileName);
out.putNextEntry(entry);
int read;
byte b[] = new byte[BUFFER];
while((read = bis.read(b, 0, BUFFER)) != -1){
out.write(b, 0, read);
}
bis.close();
out.close();
}catch(FileNotFoundException e){
e.printStackTrace();
}catch(IOException e){
e.printStackTrace();
}
} public void doZipDecompress(String inputFileName, String outputFileName){
try{
FileInputStream fis = new FileInputStream(inputFileName);
CheckedInputStream cis = new CheckedInputStream(fis, new Adler32());
ZipInputStream zis = new ZipInputStream(new BufferedInputStream(cis));
ZipEntry entry;
while((entry = zis.getNextEntry()) != null){
FileOutputStream fos = new FileOutputStream(outputFileName);
BufferedOutputStream bos = new BufferedOutputStream(fos, BUFFER);
int read;
byte b[] = new byte[BUFFER];
while((read = zis.read(b, 0, BUFFER)) != -1){
bos.write(b, 0, read);
}
bos.flush();
bos.close();
}
zis.close();
}catch(FileNotFoundException e){
e.printStackTrace();
}catch(IOException e){
e.printStackTrace();
}
}
Connection conn = this.getConnection();
conn.setAutoCommit(false);
PreparedStatement ps = conn.prepareStatement(sql);
ps.setBinaryStream(4,this.getFileInputStream(tihs.getFile_path()),this.getFileInputStreamLength(this.getFile_path()));
如果是这样,你只需要吧,在连接的地址上,把绝对路径给上就可以了,比如:
这里注意java里面"\"是转移字符,要用"\\".
<td><a href="c:\a.txt" target="_blank">file</a></td>
<a href='xxx.asp?id=xx'>下载txt文件</a>
<td><a href="<%=aa%>" target="_blank">file</a></td>