response.getOutputStream, ftp, & servlets

Z

Zaphod

Hi All,

I have been pulling my hair out the past few days trying to get arrive at
a solution to my problem and no apis, docs or googling has helped yet. I
am using apache commons ftp to stream a file from the ftp server down to
a clients browser via a servlet. That part works great I'm happy to say.
The part I'm having a problem with is trying to display another page
(like a 'Thank you for downloading this file' after completion or an
error page once the file has been transfered (or failed).

How can I display another page once the transfer is complete? The
relevant code is below. Oh, the application server being used is
Broadvision 7.1.

I did read that you cannot have a getOutputStream and a getWriter in the
same servlet, but forwarding or redirecting to a new servlet/jsp page
does not seem to work. I have tried many different combinations of flush
(), flushBuffer(), reset(), resetBuffer(), flushToilet() on the
outputstream and on the response so far to no success.

I have a jsp that calls the servlet that does a database lookup to find
the file and validate the users input from the jsp page.

jsp code to call servlet:
RequestDispatcher rd = request.getRequestDispatcher("ReceiveServlet");
rd.forward(request,response);

Servlet code that
response.setContentType("application/octet-stream");
response.setHeader("Content-disposition", "attachment;filename=\"" +
db.getFileName() + "\"");
// Get the response object output stream
ServletOutputStream outs = response.getOutputStream();
// Initiate file retrieval
ftpConn.retrieveFile(fileName, outs);

ftpConn.logout(); ftpConn.disconnect();
outs.flush(); outs.close(); // tried with & without
// All works fine up to here...

//response.resetBuffer();
RequestDispatcher rd = request.getRequestDispatcher(nextPage);
rd.forward(request,response);
// also tried instead of forward, response.sendRedirect(nextPage);


Thanks for your help
Jon
 
G

gimme_this_gimme_that

Try this ...

Create three jsp pages ...

1. A jsp page page with a message saying "Please Wait File Uploading"
On this page have a meta tag forward that waits for the file to
upload.
This jsp must also do the work of ftping the file.

2. A jsp page that checks that the data has been uploaded
If the data isn't there yet redirect to JSP 3.

3. A jsp page that looks like either renders like
JSP1 (with at meta refresh to JSP2) if the file hasn't
downloaded which renders as a confirmation page
if the file has uploaded.

To to travelocity and watch what happens when you schedule
a flight. It should look like that. Look at the meta refresh tags.
 
S

satish

hello zaphod,

please tell me how to use apache commons net
i have download the package
but tell me hoe to upload and downliad files to webserver usinf FTP in
JSP

please tell me
please
help.

thanks to you.
 
A

Arnaud Berger

Hi,

There are plenty of good examples in the commons-net package itself.

Regards,

Arnaud

(sorry everyone for the cross-answer)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top