Thursday, February 16, 2006

Virtual Directory Mapping feature in WebLogic - Tips

In WebLogic server, using deployment descriptor elements we can define Virtual directory for application.

Each weblogic application will have "weblogic.xml". This file will have deployment descriptor elelments for the application. One of the deployment descriptor element is .

We can use the virtual-directory-mapping element to specify document roots other than the default document root of the Web application for certain kinds of requests, such as image requests. When we run multiple applications, which requires same image files then all images can be stored in single location. This way we can avoid loading all the images with each application also increasing the volume of the application EAR file.

For an incoming request, if a virtual directory has been specified servlet container will search for the requested resource first in the virtual directory and then in the Web application's original document root. This defines the precedence if the same document exists in both places.

Example:


<virtual-directory-mapping>
     <local-path>c:/usr/gifs</local-path>
     <url-pattern>/images/*</url-pattern>
     <url-pattern>*.jpg</url-pattern>
</virtual-directory-mapping>
<virtual-directory-mapping>
     <local-path>c:/usr/common_jsps.jar</local-path>
     <url-pattern>*.jsp</url-pattern>
</virtual-directory-mapping>



REMEMBER: The WebLogic Server implementation of virtual directory mapping requires that you have a directory that matches the url-pattern of the mapping. The image example requires that you create a directory named images at c:/usr/gifs/images. This allows the servlet container to find images for multiple Web applications in the images directory.

No comments: