You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Drew Kidder <An...@Tivoli.com> on 2000/10/09 16:53:30 UTC

Servlet context and returned files

>I posted this a while back, but haven't seen a response, so I thought I'd 
>try posting again.  Here's the deal:
>
>I have a servlet, say "MyServlet", that I'm using to do various 
>things.  One of those things is managing file transfer and bandwidth 
>throttling. The user is presented with several links which represent files 
>that live in the /usr/apache/htdocs directory.  The actual anchor is 
>"http://my.server.com/MyServlet?name=MyFile.pdf" or something like 
>that.  The user clicks the link, the servlet strips off the 'name' 
>argument, and then goes to get the file and downloads it with a server 
>output stream.
>
>Anyhoo...
>
>What happens is that when I click the link, it returns the file - but 
>instead of having the correct filename of "MyFile.pdf", it has the name 
>"MyServlet.pdf". It doesn't matter what file I click, I'll always get a 
>filename of "MyServlet" with the proper extension appended on at the end. 
>The file downloads correctly and such, but is named improperly.
>
>Is this an issue with the servlet container? Is something not correct in 
>my setup? How can I keep the name from changing to the name of the 
>servlet?  This is a rather frustrating bug, and I'm not really sure where 
>to start looking.
>
>Thank you.


------
Andrew Kidder
L3 SW/Support Engineer, IBU
Tivoli Systems

512-436-4544
akidder@tivoli.com
http://www.tivoli.com



Re: Servlet context and returned files

Posted by kenneth topp <ca...@prodigy.net>.
This is a browser/w3c issue.  There is no method to provide naming hints
on downloaded files at all.  The browser uses what it wants from the url,
and it's behavior is more observed, rather then defined :(

But, there is a solution, I'd recommend doing a URI mapping like:

/myservlet/* -> myServlet.  (this is standard web.xml fare)

And have your servlet instead of getParameter("name") use
  getRequestUri().substring("/myserlvet/".length(), getRequestUri().length() )

The url's will now be:

 /myservlet/MyFile.pdf

That way, the browser will use the filename, MyFile.pdf, and that's what
you want, no?

Kenneth Topp

On Mon, 9 Oct 2000, Drew Kidder wrote:

> 
> >I posted this a while back, but haven't seen a response, so I thought I'd 
> >try posting again.  Here's the deal:
> >
> >I have a servlet, say "MyServlet", that I'm using to do various 
> >things.  One of those things is managing file transfer and bandwidth 
> >throttling. The user is presented with several links which represent files 
> >that live in the /usr/apache/htdocs directory.  The actual anchor is 
> >"http://my.server.com/MyServlet?name=MyFile.pdf" or something like 
> >that.  The user clicks the link, the servlet strips off the 'name' 
> >argument, and then goes to get the file and downloads it with a server 
> >output stream.
> >
> >Anyhoo...
> >
> >What happens is that when I click the link, it returns the file - but 
> >instead of having the correct filename of "MyFile.pdf", it has the name 
> >"MyServlet.pdf". It doesn't matter what file I click, I'll always get a 
> >filename of "MyServlet" with the proper extension appended on at the end. 
> >The file downloads correctly and such, but is named improperly.
> >
> >Is this an issue with the servlet container? Is something not correct in 
> >my setup? How can I keep the name from changing to the name of the 
> >servlet?  This is a rather frustrating bug, and I'm not really sure where 
> >to start looking.
> >
> >Thank you.
> 
> 
> ------
> Andrew Kidder
> L3 SW/Support Engineer, IBU
> Tivoli Systems
> 
> 512-436-4544
> akidder@tivoli.com
> http://www.tivoli.com
> 
>