Tomcat7开启SSI功能
1.官方参考文档地址:
http://httpd.apache.org/docs/current/howto/ssi.html#basicssidirectives
https://tomcat.apache.org/tomcat-7.0-doc/ssi-howto.html
2.配置步骤
(1)修改tomcat根目录下的conf文件夹中的context.xml,修改如下:
~~~xml
<Context privileged="true">
<!-- Default set of monitored resources -->
<WatchedResource>WEB-INF/web.xml</WatchedResource>
</Context>
~~~
即在Context 中增加privileged="true"
(2)修改tomcat根目录下的conf文件夹中的web.xml,将SSI的Servlet的配置取消注释,并增加编码配置,否则可能出现乱码
~~~xml
<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>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>
<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>false</param-value>
</init-param>
<load-on-startup>4</load-on-startup>
</servlet>
~~~
取消SSI Servlet的mapping注释,增加*.html,因为我们是在html中引入shtml的,如果不配置*.html,则tomcat不会处理html中的ssi指令
~~~xml
<servlet-mapping>
<servlet-name>ssi</servlet-name>
<url-pattern>*.shtml</url-pattern>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
~~~