tomcat 下使用 shtml
现以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注释
解决:Filter of class org.apache.catalina.ssi.SSIFilter is privileged and cannot be loaded by this web application
将tomcat 的server\lib目录下servlets-ssi.renametojar文件重命名为servlets-ssi.jar。
tomcat版本6.X
你也可能遇到了:java.lang.SecurityException: Filter of class org.apache.catalina.ssi.SSIFilter is privileged and cannot be loaded by this web application
【1】$CATALINA_BASE/conf/servlet.xml下的当前项目的 Context中加入了privileged="true"的属性。
3.我使用的版本 6.0.13中
$CATALINA_BASE/conf/下还有一个context.xml 这里面也有一个context的元素, 加上 privileged="true" 属性后,再启动,这次启动成功了
补充:以上的配置并没有解决乱码问题
乱码的解决:在
$CATALINA_BASE/conf/web.xml中的ssi servlet配置中添加以下初始配置:
<init-param>
<param-name>inputEncoding</param-name>
<param-value>utf-8</param-value>
</init-param>
<init-param>
<param-name>outputEncoding</param-name>
<param-value>utf-8</param-value>
</init-param>
其中
utf-8应该与你页面的编码方式相同
在shtml页面里
<!--#include file="test.html"-->就可以引用静态文件了