| 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
|
|
|
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.
|
 |
 |
|
|
subject: how to access an external file into a web application
|
|
|