SetHeader problem when user downloads a file from a server

Advertisement
Hi everyone,
I have a question about the way to let a user download a file. A created a jsp that handles the download. This is the code:
<%@ page import="java.io.*" %><%
    response.setHeader("Content-Disposition", "attachment; filename=" + session.getAttribute("executedCommand").toString());
    response.setContentType("text/csv");
    int iRead;
    FileInputStream stream = null;
    try {
        File f = new File(session.getAttribute("executedCommand").toString());
        stream = new FileInputStream(f);
        while ((iRead = stream.read()) != -1) {
            out.write(iRead);
        out.flush();
    }finally {
        if (stream != null) {
            stream.close();
%>When I run this, I get a download window, so that the right file can be downloaded, but I would like the application to show me the name of that file in the download window and in my save dialog, and that's something I haven't managed to do yet, because I always get the name of the servlet (that redirects to the jsp page). So the problem is, the right file is downloaded but it's name is never shown in the download window. How can I resolve that?
Thanks for your help!
E_J
Advertisement

Replay

I forgot to say that my session variable contains the absolute path of the file the user can download. Maybe using session variables is not the best solution in this case, but it should have to work, shouldn't it?
Still waiting for some help. I really appreciate it...
E_J