File Serving enabled

When dealing with static content (HTML pages, images, style sheets, and so on), you can choose to have these resources served by WebSphere, or have them served by the HTTP server itself.

If you want WebSphere to serve the static content of your application, you must enable file servlet, also known as the file serving servlet or file serving enabler. This servlet serves up any resource file packaged in the WAR file. The File serving enabled attribute is set to true by default. By changing it to false, the Web server plug-in will not send requests for static content to WebSphere, but leave it up to the HTTP server to serve them.

If you want the Web server to serve static content, you can experience better performance than using WebSphere in this instance, because the Web server is serving the content directly. Moreover, a Web server has more customization options than the file servlet can offer.

Once you enable the file serving enabled, you can also set following additional attributes to customize its behavior


  • bufferSize: Sets buffer size that is used for serving static files.

  • extendedDocumentRoot: Enables you to configure an application with one or more directory paths from which you can serve static files and Java ServerPages (JSP) files. You can use this attribute when an application requires access to files that exist outside of the application Web archive (WAR) directory. For example, if several applications require access to a set of common files, you can place the common files in a directory to which you can link each application as an extended document root directory.Use this attribute in addition to the contextRoot attribute.

  • file.serving.patterns.allow: Specifies that only files matching the specified pattern are served.

  • file.serving.patterns.deny: Specifies that files that match the specified file pattern are denied



The extendedDocumentRoot can be used to handle some very interesting use cases. Lets assume that you have 2-3 web applications all of them use same JavaScript framework and images. So instead of copying those files in every .war file you can copy them on file system and set it as extendedDocumentRoot.

I tried modifying my web application to try this feature. I did set value of extendedDocumentRoot property to c:/temp/images like this




Now i can access every file in the c:/temp/images folder as if it is in the context root of original web application ex. i had sample.js in c:/temp/images so i can access it by going to http://localhost:9081/webappext/sample.js

You can download the sample code from here

1 comment:

svlada said...

I have read your article and it is very interesting. Is it possible to server JSP files using extended document root, and how to achieve that?