tags:

views:

156

answers:

1

Hi, If I want to display an image in my webpage and its src is a file outside context root. At the IDE, the image is shown to be loaded.

But when I test the web page, nothing displayed. How can I config weblogic server to allow the image to be displayed. If not is there anyway to run around this problem.

Thanks a lot.

+1  A: 

You can use the Virtual Directory Mapping feature (that you declare in the weblogic.xml):

Using the virtual directory mapping feature, you can create one directory to serve static files such as images for multiple Web Applications. For example, you would create a mapping similar to the folowing:

<virtual-directory-mapping>
  <local-path>c:/usr/gifs</local-path>
  <url-pattern>/images/*</url-pattern>
</virtual-directory-mapping>

A request to http://localhost:7001/mywebapp/images/test.gif will cause your WebLogic Server implementation to look for the requested image at: c:/usr/gifs/images/*.

This directory must be located in the relative uri, such as "/images/test.gif".

Pascal Thivent
Hi Pascal. Have you tried this before? I tried to use this one but it doesn't work. If it works for you maybe I need to config anything else?
Khue Vu
@khue I'm aware of this feature since WebLogic 6 and I believe it would be known if it wasn't working. I'm thus tempted to think that their is a configuration mistake on your side. Maybe update the question to explain what you did exactly, show your configuration.
Pascal Thivent
Hi Pascal, Thanks so much for your answer. I tried it again and it worked. Maybe I did it wrong somewhere last time.
Khue Vu
%s/their/there/g
Pascal Thivent
Hi Pascal, Is there anyway we can map the different local-path to the same url-pattern? Normally the there will be error says that the MBEadn is already defined
Khue Vu
@khue No, that's not possible and this sounds logical to me (Where should weblogic look at in that case? What if the same file exists in both location? etc).
Pascal Thivent
My argument is that: Normally weblogic might set precedence for its search. In fact, weblogic looks at the virtual document path first then if it does not find the file, it looks at its context root. I think it can do the same for multiple local path (looks at the one defined first first) Yup, but if it is not possible, I have to find another way. So I need to define virtual-directory programmatically. I found the package: weblogic.j2ee.descriptor which contains necessary classes and method for defining it. But I can't find any documents regarding to this API. Any suggestion?
Khue Vu
My app will need to access file from anywhere in harddisk at runtime, Previously i planed to map every drive: D:/ --> to /*; C:/ --> to /*. But as it is only one "/*" virtual path allowed. So if virtual path not work, should I use filestreaming right? I am not really clear about it.
Khue Vu
@khue Maybe if you explain why you need that I could think of a solution. But I currently don't understand your requirement. Why don't you just put all images in one directory?
Pascal Thivent
Hi Pascal, My web application will allow the user to browse and play media files saved in the harddisk of the server. As the files can be saved anywhere, it is required the webapp has to access different directories.
Khue Vu
@khue I see. Is this going to run on Windows? Do you plan to use an Apache frontend? Maybe you could use symlinks. But exposing your entire disks sounds a bit weird and unsecure to be honest.
Pascal Thivent
Thanks Pascal. I tried symlinks and it works :D. You are of so much help.
Khue Vu
@khue You're welcome. Glad you found a solution. Maybe you could accept this answer then (the green tick below the vote counter)?
Pascal Thivent
Yeah, I accepted it. Thanks Pascal. Sorry for late reply, I didn't receive notification.
Khue Vu