aspose file tools*
The moose likes Servlets and the fly likes how to access an external file into a web application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "how to access an external file into a web application" Watch "how to access an external file into a web application" New topic
Author

how to access an external file into a web application

saipraneeth nallapareddy
Ranch Hand

Joined: Dec 02, 2009
Posts: 159
i want access to a file(image) into my web application, this file will not be in my .war file i want to access this file.

i came to know one of the way is to specify the particular file in the web.xml file and then by calling the this.class.getResource() is this a valid way of access an external file, because i am unable to figure out which is the particular tag to achieve this.

is there any other way.

can one help me in this issue.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60071
    
  65

An external file will have to have its filer path known, and you would use normal Java File I/O to access it. It could then be streamed as the response if desired.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Enrico Oliosi
Greenhorn

Joined: Aug 26, 2010
Posts: 10
I think that the best thing is create a properties file and set a variable path to your file

then you can read the filesystem path to your image from this properties file.
For reading properties file you can use ResourceBoundle.

Enrico
Michael Angstadt
Ranch Hand

Joined: Jun 17, 2009
Posts: 272

saipraneeth nallapareddy wrote:i came to know one of the way is to specify the particular file in the web.xml file and then by calling the this.class.getResource() is this a valid way of access an external file, because i am unable to figure out which is the particular tag to achieve this.


This technique requires that the file be inside the classpath of the application, which means that it will be packaged up in the WAR along with all the application's class files. The String that you pass into getResource() is the path to the file. For example, if I put an image inside of the "com.example.images" package, I can access the file like so:



SCJP 6 || SCWCD 5
saipraneeth nallapareddy
Ranch Hand

Joined: Dec 02, 2009
Posts: 159
thank you every one for the replies

@Bear Bibeault
An external file will have to have its filer path known, and you would use normal Java File I/O to access it. It could then be streamed as the response if desired.


thank you it was the way i implemented it, made use of FileInputStream and convert into buffer and write it to a OutpuStream, it did worked.

@Michael Angstadt

I got the point what you have tried to convey, useful one thank you.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to access an external file into a web application
 
Similar Threads
how one service() handles different requests???
Anyone used DAO access webservices and passed?
How to call external WAR file in J2EE Project using WSAD 5.1.1
Webservices URL in wsdl - configurable?
path issue regarding tomcat server