aspose file tools*
The moose likes Servlets and the fly likes access a image file which is outside war file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "access a image file which is outside war file" Watch "access a image file which is outside war file" New topic
Author

access a image file which is outside war file

Sudha Govindarajan
Greenhorn

Joined: Dec 08, 2008
Posts: 1
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

Joined: Aug 02, 2003
Posts: 231
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.


Regards,
Sivaraman.L
Rajah Nagur
Ranch Hand

Joined: Nov 06, 2002
Posts: 239
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?


You can't wake a person who is <b><i>pretending</i></b> to be asleep.<br />Like what <b>"it"</b> does not like - <i> Gurdjieff </i>
Nitesh Kant
Bartender

Joined: Feb 25, 2007
Posts: 1638

Moving to Servlets forum for you. You may get better answers there


apigee, a better way to API!
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61218
    
  66

If it's not part of a web application, it cannot be directly addressed by URL.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

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.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
raj malhotra
Ranch Hand

Joined: Feb 22, 2007
Posts: 285
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

Joined: Oct 08, 2006
Posts: 2458
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: access a image file which is outside war file