• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

access a image file which is outside war file

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I want to access an image file(which is outside the war file where the folder of image file is protected by credentials)from a war file where the image file and war file are located in the same server.

Anyone please help me?

Thanks in advance.

regards,
sudha.
 
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Sudha,
Is the war file and the image file are in the same directory? If yes and if you are able to access the war file you should be able to access the image file as well.
 
Ranch Hand
Posts: 239
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Sudha Govindarajan:
Hi,

I want to access an image file(which is outside the war file where the folder of image file is protected by credentials)from a war file where the image file and war file are located in the same server.

Anyone please help me?

Thanks in advance.

regards,
sudha.



Have you tried accessing this? Are you getting any error?
What is your approach that has been attempted?
 
Bartender
Posts: 1638
IntelliJ IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving to Servlets forum for you. You may get better answers there
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If it's not part of a web application, it cannot be directly addressed by URL.
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We have a project in our CodeBarn named SimpleStream that shows how to make a servlet for streaming binary data (in this case images) to the client.

In the demo project, the files are being read with context.getResourceAsStream. You won't be able to do this if the files are outside of your web application's directory structure. You'll need to change it to use a FileReader.

This should be enough to get you on the right track.
 
Ranch Hand
Posts: 294
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How about <c:import> jstl tag? It can access a URL even if the resource is on other server.
Please correct me if i am wrong.

thanks
Raj
 
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The SimpleStream example isn't very suitable as it relies on the classpath. You either have to add the path to the images to the classpath, or to use FileInputStream (and thus certainly not FileReader) to read imags from local disk.

Here's an example of a servlet which does exactly that: http://balusc.blogspot.com/2007/04/imageservlet.html

About the JSTL's c:import tag: this is not suitable either. It can only access resources in own context, or the other contexts, or just by an external (absolute) URL.
reply
    Bookmark Topic Watch Topic
  • New Topic