孤独的猫

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
想让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://hi.baidu.com/lutingge/blog/item/3addedfda404fd85b801a07c.html

posted on 2012-06-14 21:01  孤独的猫  阅读(306)  评论(0编辑  收藏  举报