wood burning stoves*
The moose likes Servlets and the fly likes store a file in the server Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "store a file in the server" Watch "store a file in the server" New topic
Author

store a file in the server

Sherif Shehab
Ranch Hand

Joined: Mar 05, 2007
Posts: 483

Hi pals,

i got a servlet is going to connect to a DB then do some queries then write the result in excel file on the local hard disk , what i wanna instead writing the file on the local hard disk i wanna to store it on the tomcat in a specific path so it can be downloaded ,

Any suggestions ?


Thanks,
Sherif
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Why do you want to store it on the file system rather than streaming directly to the client?
Sherif Shehab
Ranch Hand

Joined: Mar 05, 2007
Posts: 483

Because i need to keep it on the server for a while(1 week) , and to be able to be downloaded anytime later with out running my servlet.

Any advice?
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Are there any security or authentication issues? getting the file and writing to the Tomcat server using the Tomcat server isn't difficult, if you need to restrict who sees what, than this will affect the design.
Sherif Shehab
Ranch Hand

Joined: Mar 05, 2007
Posts: 483

Originally posted by David O'Meara:
Are there any security or authentication issues? getting the file and writing to the Tomcat server using the Tomcat server isn't difficult, if you need to restrict who sees what, than this will affect the design.


No security concerns i'll put a link in the index page to access the archived files. actually i goggled a lot but i cant find anything useful.
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Easiest then is to write them into a directory in the application context (but not in the WEB-INF directory) and allow directory browsing.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61103
    
  66

Personally, I'd recommend against storing the files within the body of the web application. By doing so, you create complications with upgrades and redeployment. I've done setups like this many times and I store the files independently of the web app so that I can upgrade and redeploy the web app without worrying about clobbering the files,

Access to the files is granted through a servlet that reads the files from the file system and streams them to the client upon demand.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Sherif Shehab
Ranch Hand

Joined: Mar 05, 2007
Posts: 483

so you recommend streaming upon demand? OK good idea but what if the client wanna access the old files? because like i mentioned before the is reporting tool.
Any advice ?
Angel J Gama
Ranch Hand

Joined: Jun 28, 2007
Posts: 36
My suggestion is to stream the file upon demand. If the record you're going to include in the file is likely to change, you could create a temporary table where you can store a copy of that record. Later, you can delete the temporary record instead of a file.
I feel that much secure, and probably space-saving.
Sherif Shehab
Ranch Hand

Joined: Mar 05, 2007
Posts: 483

i think making this function from scratch will take long time , because i already got the function that writes to local hard dish up and running and the project time is to strict , this why i went for modifying the exist method from writing on HDD to write on server...
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12769
    
    5
Think about this - how is your client supposed to locate this output?

Do they get a link to the excel file in an HTML page you return to them? If so then that link could point to a servlet that knows how to locate the file and write it to the output stream will the appropriate headers so that the client's browser will recognize it correctly.

Servlets to accomplish this are quite simple, I think that Bear has an example on his web site.

Bill
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61103
    
  66

Actually the excellent examples are on Ben's site.
Sherif Shehab
Ranch Hand

Joined: Mar 05, 2007
Posts: 483

ok i got it, thanks pals for your support...
 
 
subject: store a file in the server