• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to store a file on server

 
sridhar lakka
Ranch Hand
Posts: 109
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
sridhar lakka
Ranch Hand
Posts: 109
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic