You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Dr NoName <sp...@yahoo.com> on 2005/03/06 22:27:09 UTC
setting download file name
Hi all,
I am trying to make link to a dynamically generated
zip file which the user can download. It links to a
jsp page like so:
<a href="audio_download.jsp">Download Audio</a>
In audio_download.jsp, I have the following code to
generate the zip:
<jsp:useBean scope="session" id="myLatestAudioFiles"
class="java.util.ArrayList"/>
<%
response.setContentType("application/zip");
if( ! myLatestAudioFiles.isEmpty() )
{
ZipOutputStream ostr = new ZipOutputStream(
response.getOutputStream() );
for(int i = 0; i < myLatestAudioFiles.size();
i++)
{
String file_path =
(String)myLatestAudioFiles.get(i);
String file_name =
CFunctions.splitPathName(file_path)[1];
InputStream istr = new
FileInputStream(file_path);
ostr.putNextEntry( new ZipEntry(file_name)
);
CFunctions.copyStream(istr, ostr);
istr.close();
}
ostr.close();
}
%>
This works but when the user clicks the link, the save
file dialog's default file name is audio_download.jsp.
I want it to be a dynamically generated zip file name
(something like 087_latest_audio.zip). How do I do
that? Or is this the wrong approach?
thanks in advance,
Eugene
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
Re: setting download file name
Posted by Dr NoName <sp...@yahoo.com>.
that works. thanks.
Eugene
--- Darren Govoni <dg...@metadapt.com> wrote:
> Try this. I used it for JNLP, but it should work for
> zip. Just
> replace .jnlp with .zip
>
> String fileName = request.getServletPath();
> fileName =
> fileName.substring(fileName.lastIndexOf("/") + 1);
> fileName = fileName.substring(0,
> fileName.indexOf(".")) + ".jnlp";
> response.addHeader("Content-Disposition", "Inline;
> fileName=" +
> fileName);
>
>
> On Sun, 2005-03-06 at 13:27 -0800, Dr NoName wrote:
>
> > Hi all,
> >
> > I am trying to make link to a dynamically
> generated
> > zip file which the user can download. It links to
> a
> > jsp page like so:
> >
> > <a href="audio_download.jsp">Download Audio</a>
> >
> > In audio_download.jsp, I have the following code
> to
> > generate the zip:
> >
> > <jsp:useBean scope="session"
> id="myLatestAudioFiles"
> > class="java.util.ArrayList"/>
> > <%
> > response.setContentType("application/zip");
> > if( ! myLatestAudioFiles.isEmpty() )
> > {
> > ZipOutputStream ostr = new
> ZipOutputStream(
> > response.getOutputStream() );
> > for(int i = 0; i <
> myLatestAudioFiles.size();
> > i++)
> > {
> > String file_path =
> > (String)myLatestAudioFiles.get(i);
> > String file_name =
> > CFunctions.splitPathName(file_path)[1];
> > InputStream istr = new
> > FileInputStream(file_path);
> > ostr.putNextEntry( new
> ZipEntry(file_name)
> > );
> > CFunctions.copyStream(istr, ostr);
> > istr.close();
> > }
> > ostr.close();
> > }
> > %>
> >
> >
> > This works but when the user clicks the link, the
> save
> > file dialog's default file name is
> audio_download.jsp.
> > I want it to be a dynamically generated zip file
> name
> > (something like 087_latest_audio.zip). How do I do
> > that? Or is this the wrong approach?
> >
> >
> > thanks in advance,
> >
> > Eugene
> >
> >
> > __________________________________________________
> > Do You Yahoo!?
> > Tired of spam? Yahoo! Mail has the best spam
> protection around
> > http://mail.yahoo.com
> >
> >
>
---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> tomcat-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail:
> tomcat-user-help@jakarta.apache.org
>
__________________________________
Celebrate Yahoo!'s 10th Birthday!
Yahoo! Netrospective: 100 Moments of the Web
http://birthday.yahoo.com/netrospective/
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
Re: setting download file name
Posted by Darren Govoni <dg...@metadapt.com>.
Try this. I used it for JNLP, but it should work for zip. Just
replace .jnlp with .zip
String fileName = request.getServletPath();
fileName = fileName.substring(fileName.lastIndexOf("/") + 1);
fileName = fileName.substring(0, fileName.indexOf(".")) + ".jnlp";
response.addHeader("Content-Disposition", "Inline; fileName=" +
fileName);
On Sun, 2005-03-06 at 13:27 -0800, Dr NoName wrote:
> Hi all,
>
> I am trying to make link to a dynamically generated
> zip file which the user can download. It links to a
> jsp page like so:
>
> <a href="audio_download.jsp">Download Audio</a>
>
> In audio_download.jsp, I have the following code to
> generate the zip:
>
> <jsp:useBean scope="session" id="myLatestAudioFiles"
> class="java.util.ArrayList"/>
> <%
> response.setContentType("application/zip");
> if( ! myLatestAudioFiles.isEmpty() )
> {
> ZipOutputStream ostr = new ZipOutputStream(
> response.getOutputStream() );
> for(int i = 0; i < myLatestAudioFiles.size();
> i++)
> {
> String file_path =
> (String)myLatestAudioFiles.get(i);
> String file_name =
> CFunctions.splitPathName(file_path)[1];
> InputStream istr = new
> FileInputStream(file_path);
> ostr.putNextEntry( new ZipEntry(file_name)
> );
> CFunctions.copyStream(istr, ostr);
> istr.close();
> }
> ostr.close();
> }
> %>
>
>
> This works but when the user clicks the link, the save
> file dialog's default file name is audio_download.jsp.
> I want it to be a dynamically generated zip file name
> (something like 087_latest_audio.zip). How do I do
> that? Or is this the wrong approach?
>
>
> thanks in advance,
>
> Eugene
>
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam? Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org