?
Solved

How to download files from remote application server?

Posted on 2003-03-06
3
Medium Priority
?
181 Views
Last Modified: 2013-11-24
Do you know how to download files from remote application server? I don't know whether I need to create a session bean which returns a file back to the servlet and save it under webApplication, and then make a link to the file in jsp page to enable the user to download. But the problem is that how to clean those files.
Some of those files are lvery large. I'm looking for the best solution.

Thanks for the help in advance!

0
Comment
Question by:DevelHelper
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 9

Expert Comment

by:Venci75
ID: 8080498
you can use servlet:
response.setHeader("Content-Disposition", "attachment; filename=filename;");
response.setHeader("Content-Type", "application/octet-stream");

response.getOutputStream().write(); // white the file data
0
 

Accepted Solution

by:
doddjames earned 320 total points
ID: 8080837

Hey,

If your EJB container and servlet container are the same, or they both have access to the same filesystems, then obviously don't bother with the session bean.  If you're getting your content from a database and using EJBs then it seems sensible to have a servicing session bean provide the content.

If the files are static, oft-downloaded and are not sensitive then the best approach may be to store them in a special area that people can download from.  Otherwise, don't bother writing them to the filesystem.  If you do for some reason decide to cache the file locally, you can save to a temporary file:

InputStream in = myService.getContent( myCriteria );
File temp = File.createTempFile( "download", ".dat" );
OutputStream out = new FileOutputStream( temp );
..write in to out..
in.close();
out.close();

As the previous answer suggests, you can then just write the content to the ServletOutputStream that the JSP or Servlet's ServletResponse object will supply you with.

0
 

Author Comment

by:DevelHelper
ID: 8081045
In my case, EJB container and Servlet container are not same (different machines). So based on Dodddiames's suggestion, it doesn't request to save the file which return from the remote EJB session bean when make the following call, right?

OutputStream out = new FileOutputStream( file );
0

Featured Post

Linux Academy Android App Now Supports Chromecast

We have some fantastic news for our Android fans. We’re so excited to announce that the Linux Academy Android app is now available with Chromecast support. That’s right – simply download the latest update of the Linux Academy App and start casting your favorite course videos!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Suggested Courses
Course of the Month15 days, 17 hours left to enroll

741 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question