随笔-153  评论-235  文章-19  trackbacks-0
    想让Tomcat支持ssi,一般是shtml文件。配置比较简单。

默认tomcat不支持ssi。

现以tomcat5.5.x为例。

改conf/web.xml配置。

有两种方式:一是servlet,二是filter。

servlet方式的:
<!--
    <servlet>
        <servlet-name>ssi</servlet-name>
        <servlet-class>
          org.apache.catalina.ssi.SSIServlet
        </servlet-class>
        <init-param>
          <param-name>buffered</param-name>
          <param-value>1</param-value>
        </init-param>
        <init-param>
          <param-name>debug</param-name>
          <param-value>0</param-value>
        </init-param>
        <init-param>
          <param-name>expires</param-name>
          <param-value>666</param-value>
        </init-param>
        <init-param>
          <param-name>isVirtualWebappRelative</param-name>
          <param-value>0</param-value>
        </init-param>
        <load-on-startup>4</load-on-startup>
    </servlet>
-->

<!--
    <servlet-mapping>
        <servlet-name>ssi</servlet-name>
        <url-pattern>*.shtml</url-pattern>
    </servlet-mapping>
-->

找到上面的内容,去掉注释。

filter方式:
<!--
    <filter>
        <filter-name>ssi</filter-name>
        <filter-class>
          org.apache.catalina.ssi.SSIFilter
        </filter-class>
        <init-param>
          <param-name>contentType</param-name>
          <param-value>text/x-server-parsed-html(;.*)?</param-value>
        </init-param>
        <init-param>
          <param-name>debug</param-name>
          <param-value>0</param-value>
        </init-param>
        <init-param>
          <param-name>expires</param-name>
          <param-value>666</param-value>
        </init-param>
        <init-param>
          <param-name>isVirtualWebappRelative</param-name>
          <param-value>0</param-value>
        </init-param>
    </filter>
-->

<!--
    <filter-mapping>
        <filter-name>ssi</filter-name>
        <url-pattern>*.shtml</url-pattern>
    </filter-mapping>
-->

同样是去掉上面的注释。但是filter方式的还要加mime-mapping=text/x-server-parsed-html
<!--
    <mime-mapping>
        <extension>shtml</extension>
        <mime-type>text/x-server-parsed-html</mime-type>
    </mime-mapping>
-->

去掉mime-mapping的shtml注释。

在test的web试下:
index.shtml
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>ssi 示例</title>
</head>

<body>
ssi area 
<!--#include virtual="ssi.html" -->
<p>

        footer 
<!--#include virtual="footer.html" --><p>
        
        
<p>
            
<!--#config timefmt="%D" -->
        Me last modified 
<!--#echo var="LAST_MODIFIED" -->

</body>
</html>

footer.html
<ul>
    
<li>index</li>
    
<li>about</li>
</ul>

ssi.html
<p>this is ssi.html file</p><p>
<p>中文</p>
ssi.html file end
<p/>


现在可以,http://localhost:8080/test/index.shtml 有结果了。
posted on 2008-07-27 21:55 流浪汗 阅读(1370) 评论(0)  编辑  收藏 所属分类: Tomcat

只有注册用户登录后才能发表评论。


网站导航: