Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

access a image file which is outside war file

 
Sudha Govindarajan
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • 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.
 
Sivaraman Lakshmanan
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • 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.
 
Rajah Nagur
Ranch Hand
Posts: 239
  • Mark post as helpful
  • send pies
  • 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?
 
Nitesh Kant
Bartender
Posts: 1638
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to Servlets forum for you. You may get better answers there
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64967
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If it's not part of a web application, it cannot be directly addressed by URL.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • 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.
 
raj malhotra
Ranch Hand
Posts: 288
  • Mark post as helpful
  • send pies
  • 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
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic