This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
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
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Servlets
Reply 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: 56204
    
  13

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.


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About 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 to call external WAR file in J2EE Project using WSAD 5.1.1
Webservices URL in wsdl - configurable?
path issue regarding tomcat server
Anyone used DAO access webservices and passed?
how one service() handles different requests???