File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Relative path Issue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Relative path Issue" Watch "Relative path Issue" New topic

Relative path Issue

Madi Muthukumaran

Joined: Oct 16, 2003
Posts: 11

I am in need of help from you guys, it's very very urgent.

I will try to explain the problem. I have images stored in my server hard disk say (C:\AllImages). No I need to display the images in my web page, using the <img src=""> tag.

Now the problem is that the application server is in different folder say (F , now how will I give the relative path for the images stored in the C:

Is there any way to implement this thing. Kindly reply as soon as possible.

I deploy my application as a war, the app server can be Weblogic, Jboss, was.

ThanX in advance.

Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63865


There aren't many rules that you need to worry about here on the Ranch, but one that we take very seriously regards the use of proper names. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

JavaRanch Sheriff
[ May 05, 2006: Message edited by: Bear Bibeault ]

[Asking smart questions] [About Bear] [Books by Bear]
Joseph Erickson

Joined: May 05, 2006
Posts: 10
You won't be able to link directly to those images because they aren't in the web server's directory, but you might be able to link that folder into the web server's root document directory on the F drive. In Windows land, this would probably be done by a shortcut. You could make a shortcut of C:\Allimages, call it "images", and drop the shortcut into the Web Server's root document folder. Then the img tag should be <img src="/images/blah.gif" />

Do you know what the document root folder is for the web server?
Madi Muthukumaran

Joined: Oct 16, 2003
Posts: 11

ThanX for your reply,

I tried in Websphere 5.2, actually my application will in the form of a war file (Sample.war), so when i deployed it, it will be extracted in the <<websphere_Installation_folder>>\installedapps\nodename\Sample.war.
After i deployed i went there and created a shortcut to the mage folder in F driver. But it is not working.

I tried your option but it's not working. When i try to access image from the browser, i am getting "HTTP 404" error.

Is there any other way to that.

Madi Muthukumaran

Joined: Oct 16, 2003
Posts: 11
Thanx every one for the ur reply, i found out the solution for the issue. Instead of displaying the image using the image tag, we can directly read the image file and write it to the output stream of the response object. Following is the code sample.

String mimiMappings[] = {"application/pdf pdf PDF", "application/msword DOC doc"};
MimetypesFileTypeMap mimeType = new MimetypesFileTypeMap();

InputStream certFile = new FileInputStream(new File("ImageFile.jpg"));
OutputStream respOutStream = response.getOutputStream();

// Transfer bytes from in to out
byte[] buf = new byte[1024];
int len;
while ((len = > 0)
respOutStream.write(buf, 0, len);

I agree. Here's the link:
subject: Relative path Issue
It's not a secret anymore!