Download in jsp

Hi I am new to java and would like to know how do i make user download a file from the server to the client machine. I have googled for it but couldnt find an answer. f any body would help me out it would be greatly appreciated
[241 byte] By [mOmIna] at [2007-10-3 4:10:13]
# 1
so what was it that you wanted to be downloaded in jsp?well, you could always, just direct the link to the file you wanted to be downloaded..-Nywled
Redxxiva at 2007-7-14 22:10:26 > top of Java-index,Java Essentials,New To Java...
# 2

<%@page import="java.io.*"%>

<%

String filename = "y3.jpg";

String filepath = "c:\\tom\\webapps\\thumbnail\\";

response.setContentType("application/octet-stream");

response.setHeader("Content-Disposition",

"attachment; filename=\"" + filename+"\"");

java.io.FileInputStream fileInputStream = new java.io.FileInputStream(new File(filepath+filename));

int i;

BufferedOutputStream os = new BufferedOutputStream(response.getOutputStream());

while ((i=fileInputStream.read()) != -1) {

os.write(i);

}

fileInputStream.close();

os.close();

%>

It is better to put this code into servlet. If servlet is used, you need a html form, some setting in web.xml and a servlet. You are a beginner, download is not an easy function.

Redxxiv : Some people do not want the file can be downloaded by a hyperlink because they want the download available to the login users. If you use a hyperlink download, people can download it without login.

evilknighthka at 2007-7-14 22:10:26 > top of Java-index,Java Essentials,New To Java...
# 3

> Redxxiv : Some people do not want the file can be

> downloaded by a hyperlink because they want the

> download available to the login users. If you use a

> hyperlink download, people can download it without

> login.

Yah, that was right, if he had asked for something specific like that. all he wanted was for a file to be downloaded..

-

Nywled

Redxxiva at 2007-7-14 22:10:26 > top of Java-index,Java Essentials,New To Java...