aspose file tools*
The moose likes Servlets and the fly likes Download a File from server to client machine - web application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Download a File from server to client machine - web application" Watch "Download a File from server to client machine - web application" New topic
Author

Download a File from server to client machine - web application

Natalie Afota
Greenhorn

Joined: May 08, 2011
Posts: 4
Hey all…

I need to implement the following functionality:

I have a web application running under Apache Tomcat.
The user will have to provide a full path, choosing where to locate the file he wishes to download from the server. It is basically the opposite operation of upload.

I have encountered this issue while "Googling", trying to find an appropriate solution. The only solution which doesn’t fit was using a servlet and writing the file into the HttpServletResponse object!
I can’t use this kind of solution, since the user is been promoted with the File Download Dialog, which I am trying to avoid.

I have explored the HttpServletRequest object ,It seems I can extract the following data:
iHttpServletRequest.getRemoteAddr();
iHttpServletRequest.getRemoteHost();
iHttpServletRequest.getRemotePort();

Is there any change I can use the IP Address to achieve the above?

I hope I was clear enough, Thanks for any help (solutions or Ideas!!!)

Natalie
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19762
    
  20

Welcome to the Ranch!

I don't think this is possible, and I certainly hope I'm right. I definitely do not want to access a website that starts writing data on my hard disk (other than cookies / cache data) without asking me first. No, you're really going to have to ask your users to save the file where they want to.

You may be able to use the remote IP address if and only if the machines are accessible by a preset means like Windows file sharing. Unless you're working within your own corporate or private network, where you can enforce this, you can forget about your requirements.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61658
    
  67

Natalie Afota wrote:the user is been promoted with the File Download Dialog, which I am trying to avoid.

Not possible. Thank goodness.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Ajeeth Kumar
Ranch Hand

Joined: Mar 30, 2005
Posts: 56
I am sure that you can download the files from server using the response object and by setting the response type as "application/pdf" in the resultant jsp header.
But you can never write files to your disk automatically as it is a web application.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61658
    
  67

Ajeeth Kumar wrote:I am sure that you can download the files from server using the response object and by setting the response type as "application/pdf" in the resultant jsp header.
I am also implementing the same behaviour in a web app and it works fine in windows

Except that that will not meet the (impossible) requirements of the original poster to write the file automatically to the file system of the client machine without user intervention.
Natalie Afota
Greenhorn

Joined: May 08, 2011
Posts: 4
Hey

I will give you guys some background…

I am implementing web applications for our company internal use (in internal network!)

In this scenario, the user is expecting the file to be copied to his local drive.

I understand that in the real web achieving this kind of functionality can be a real security hazard!

The clients are running under windows but the server is running under Linux!

Having the client IP address is not enough? Using some copy file protocol something like FTP?

Still hope to find solution!

Thanks all, Natalie
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16250
    
  21

The technical name for software that silently writes files to peoples computers is "virus". So you won't get any help from standard web protocols.

Furthermore, knowing the client's IP address does you no good, since HTTP is a strict request/response protocol. It cannot send anything down to the client that's unsolicited or to anywhere but the receiving socket on the client-to-server connection. Which will be closed immediately after the response has been received.

You will need client-side code to do what you're looking for. It can be an ActiveVirus, er ActiveX control or a signed applet or something like that, but basically it's got to be something that operates outside the normal sandbox security for J2EE.

A possible alternative for Windows users might be to supply the file through Windows provisioning services, which I believe are still called "SMS", if the Marketing Department hasn't decided to "improve" the name.

Another possible alternative would be to simply keep the file on a network share that the webserver has write access writes to so that the webserver can do out-of-band writes to the file. There are good arguments for this, as long as you don't truly need the file on the user's local machine (for example for disconnected laptop use).


Customer surveys are for companies who didn't pay proper attention to begin with.
Natalie Afota
Greenhorn

Joined: May 08, 2011
Posts: 4
Hey

Tim Holloway wrote:A possible alternative for Windows users might be to supply the file through Windows provisioning services, which I believe are still called "SMS", if the Marketing Department hasn't decided to "improve" the name.



Where can I find more information regarding Windows provisioning services?

Thanks, Natalie
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61658
    
  67

I'd try google.
 
 
subject: Download a File from server to client machine - web application