Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

store a file in the server

 
Sherif Shehab
Ranch Hand
Posts: 485
Android Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ?
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do you want to store it on the file system rather than streaming directly to the client?
 
Sherif Shehab
Ranch Hand
Posts: 485
Android Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 485
Android Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64967
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Sherif Shehab
Ranch Hand
Posts: 485
Android Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 485
Android Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13064
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64967
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually the excellent examples are on Ben's site.
 
Sherif Shehab
Ranch Hand
Posts: 485
Android Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok i got it, thanks pals for your support...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic