GeeCON Prague 2014*
The moose likes Servlets and the fly likes How to store a file on server Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Servlets
Bookmark "How to store a file on server" Watch "How to store a file on server" New topic
Author

How to store a file on server

sridhar lakka
Ranch Hand

Joined: Jan 02, 2007
Posts: 109
Hi All,
Thanks a lot in advance.
We will deploy the application on websphere server through URL which is at remote place by creating ear file.
Now, I have on pdf file which is a fixed one and it wont be changed in future also and I am opening this pdf on click of a link.
Due to this large pdf my ear size become very high and some times I am facing deployment problem while uploading this large file.
Is there any way to keep the file some where in server and later we can open?.

Please help me.
Regards,
Sree
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Yes, you can write a servlet that streams binary files from the server to the browser. Then, using a context init param, you can configure the location of the file so that your streaming servlet can find it.

If you would like an example of a servlet that streams a file, we have one in our Code barn.
http://www.javaranch.com/codebarn/codebarn-servlets-simplestream.jsp

In this example, the files are being read using ServletContext.getResourceAsStream because they are located within the web app's directory structure. In your case, you would want to use a FileReader so you can read the file from disk using java.io.File.
It shouldn't be hard to convert the example servlet to do that.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
sridhar lakka
Ranch Hand

Joined: Jan 02, 2007
Posts: 109
Thanks a lot for your reply, however I dont want to store that file even in WEB-INF folder, as it will when we will create an ear.

Regards,
Sree
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

I know. You said that.
This is why I said:
In your case, you would want to use a FileReader so you can read the file from disk using java.io.File.
It shouldn't be hard to convert the example servlet to do that.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to store a file on server