Relative path Issue

Hi,

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.

Regards,

[626 byte] By [Muthu_a] at [2007-10-2 19:38:52]
# 1

> Hi,

>

> 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.

>

> Regards,

Hi,

To solve this problem you can use one of the following ways ,

1.TrygetServletContext().getRealPath(".") . it returns your application path.

you need to deploy your images inside your web application.

you could use image tag as follows

<img src="<%=application.getRealPath(".")%>/images/one.jpg">

2. Store the path of your images folder in web.xml with any servlet which is having a code to treat that init value you have givenand set the init value into session after reading it from servlet.

web.xml

<servlet>

<servlet-name> InitServlet </servlet-name>

<servlet-class>com.xxx.InitServlet</servlet-class>

<init-param>

<param-name> IMAGE_FOLDER </param-name>

<param-value> F:/ </param-value>

</init-param>

</servlet>

<img src="<%=application.getAttribute("IMAGE_FOLDER")%>/one.jpg" >

But disadvantage of this method is if you change the location of image folder,

you need to update with web.xml

thanks,

nvseenu

nsrininasa at 2007-7-13 21:27:37 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

I don't know how you expect a user browsing your website from another computer to arrive at

F:\directory\image.jpg

The images have to reside under the root of your webapp. Otherwise they're not visible to the web-user.

<img src="<%=application.getAttribute("IMAGE_FOLDER")%>/one.jpg" >

This WEB-INF hard-coded path is not a good idea either because 1. you lose portability, and 2. It just won't work (at least in the way shown above). Try moving your image directory under your deployed webapps directory so that it becomes available as

http://www.myserver.com/images

Or something along those lines

Charlie

Message was edited by:

charlie.roche

charlie.rochea at 2007-7-13 21:27:37 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

First I would thank you for ur prompt response.

I had forgotten to mention that our application would in a form of a war file that will be deployed. And the user will upload the images at run time and I have to give a link to view the image once it抯 uploaded. I cannot give a folder under the deployed application, cause once I redeploy that application the images already uploaded will be gone. That抯 the reason I am trying to have to a different location.

Is there another way to do that.

Muthu_a at 2007-7-13 21:27:37 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
Then you can't provide direct links to the images in your HTML. One solution is to provide instead a link to an image-download servlet, with a parameter to identify the image. Then only the servlet needs to know the directory where the uploads dumped the images.
DrClapa at 2007-7-13 21:27:37 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5

Hi

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();

mimeType.addMimeTypes(mimiMappings);

response.setContentType(mimeType.getContentType(certImagePath));

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 = certFile.read(buf)) > 0)

{

respOutStream.write(buf, 0, len);

}

certFile.close();

respOutStream.flush();

respOutStream.close();

Regards

Muthu

Muthu_a at 2007-7-13 21:27:37 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6

Hello,

I have a similar problem.

I need to get one image of other url and paint in one table of my jsp. I have the same code in my java but I don't know how to write the image in jsp.

Can someone help me? Please

Many Thanks

Message was edited by:

kreator2006

kreator2006a at 2007-7-13 21:27:37 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...