デフォルトサーブレットを独自の実装でオーバーライドして、自分の web.xml
にそれを宣言して使うことが可能です。この意味が理解できるなら、デフォルトサーブレット
のコードを読んで適宜修正できるかと思います。
(理解できなければ、役に立つ方法ではありません)
localXsltFile または globalXsltFile
かどちらかを使用できます。そうすると、デフォルトサーブレットが XML 文書を生成し、
localXsltFile や globalXsltFile
で指定した値を元に、XML 文書に対して XSL 変換を実行できます。
localXsltFile、globalXsltFile
の順にチェックされ、その上でデフォルトの動作が行われます。
フォーマットは以下の通りです。
 |  |  |
 |
<listing>
<entries>
<entry type='file|dir' urlPath='aPath' size='###' date='gmt date'>
fileName1
</entry>
<entry type='file|dir' urlPath='aPath' size='###' date='gmt date'>
fileName2
</entry>
...
</entries>
<readme></readme>
</listing>
|  |
 |  |  |
type='dir' の場合、size は無視されます
- readme は CDATA エントリです
Tomcat のデフォルトの見栄えを真似たサンプル XSL ファイルを以下に示します。
 |  |  |
 |
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="xhtml" encoding="utf-8" indent="no"/>
<xsl:template match="listing">
<html>
<head>
<title>
Sample Directory Listing For
<xsl:value-of select="@directory"/>
</title>
<style>
h1{color : white;background-color : #0086b2;}
h3{color : white;background-color : #0086b2;}
body{font-family : sans-serif,Arial,Tahoma;
color : black;background-color : white;}
b{color : white;background-color : #0086b2;}
a{color : black;} HR{color : #0086b2;}
</style>
</head>
<body>
<h1>Sample Directory Listing For
<xsl:value-of select="@directory"/>
</h1>
<hr size="1" />
<table cellspacing="0"
width="100%"
cellpadding="5"
align="center">
<tr>
<th align="left">Filename</th>
<th align="center">Size</th>
<th align="right">Last Modified</th>
</tr>
<xsl:apply-templates select="entries"/>
</table>
<xsl:apply-templates select="readme"/>
<hr size="1" />
<h3>Apache Tomcat/5.0</h3>
</body>
</html>
</xsl:template>
<xsl:template match="entries">
<xsl:apply-templates select="entry"/>
</xsl:template>
<xsl:template match="readme">
<hr size="1" />
<pre><xsl:apply-templates/></pre>
</xsl:template>
<xsl:template match="entry">
<tr>
<td align="left">
<xsl:variable name="urlPath" select="@urlPath"/>
<a href="{$urlPath}">
<tt><xsl:apply-templates/></tt>
</a>
</td>
<td align="right">
<tt><xsl:value-of select="@size"/></tt>
</td>
<td align="right">
<tt><xsl:value-of select="@date"/></tt>
</td>
</tr>
</xsl:template>
</xsl:stylesheet>
|  |
 |  |  |