One thing you could try would be to change the way you create URLs for downloadable
files:

    <html>
    <head><title>Page Title</title></head>
    <body>
    <a href="/servlets/download/file1.zip">File 1</a>
    </body>
    </html>

Note that there is a slash before the filename instead of a question mark.

Now, assuming that your download servlet is mapped to "/servlets/download", you can
retrieve the name of the requested file like this:

    String str_Filename = request.getPathInfo();

which will return "/file1.zip" in the case above.  You can get rid of the leading
slash if you don't want it.

Doing things this way avoids the fact that browsers are inconsistent and/or buggy
in how they handle the content disposition header, but they default to what looks
(to them) like the last component of the request URL -- so the prompt would be to
save "file1.zip" in this case.

Craig McClanahan


Larry Hoffman wrote:

> I developed a java servlet that takes the query string from a html form.
> For example:
>
> <html>
> <head>
> <a href="/servlets/download?file1.zip">File 1</a>
> </html>
> </body>
>
> Well, I click the link to call the servlet.  The servlet takes the query
> string and appends it to the path were the file is loacted.  See code below:
>
> res.setContentType("application/x-zip-compressed");
>
> // Grab the query string passed in.
> String strQueryString = req.getQueryString();
>
> res.setHeader("Content-Disposition","filename=" + strQueryString + ";");
> ServletOutputStream out = res.getOutputStream();
>
> String  str_updateFile = "/home/httpd/bin/" + strQueryString;
>
> // Try to read in the update file information.
> try
> {
>         String fileLine;
>         FileInputStream finStream = new FileInputStream(str_updateFile);
>         int i;
>
>         while((i = finStream.read()) != -1)
>         {
>                 out.write(i);
>         }
>         finStream.close();
> }
> catch(IOException e){}
>
> out.close();
>
> The problem in the file download dialog box. from Internet Explorer.  When
> the servlet starts the download I get the following description:
>
> You have chosen to download a file from this location
>
> "...Updates?OasisEdit.1.4.0.3.zip from [server name here]"
>
> How come the "...Updates?File1.zip" show up like this.  I want it to look
> like:
>
> "File1.zip from [server name here]"
>
> Any suggestions????
>
> Thanks
> LHoffman
>
> ===========================================================================
> To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
> FAQs on JSP can be found at:
>  http://java.sun.com/products/jsp/faq.html
>  http://www.esperanto.org.nz/jsp/jspfaq.html

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
FAQs on JSP can be found at:
 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html

Reply via email to