tomcat想要使用html文件引入html文件的功能可以开启ssi,这样就可以在html文件中使用include指令,从而使得html文件可以动态加载html文件了。
开启ssi步骤如下:
1、apache-tomcat-7.0.72\conf目录下context.xml 中<Context>修改为<Context privileged="true">
2、apache-tomcat-7.0.72\conf目录下web.xml 中去掉下面代码的注释
a、
<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>0</param-value>
</init-param>
<load-on-startup>4</load-on-startup>
</servlet>
b、
<servlet-mapping>
<servlet-name>ssi</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
并加上<url-pattern>*.shtml</url-pattern>
之后变成
<servlet-mapping>
<servlet-name>ssi</servlet-name>
<url-pattern>*.html</url-pattern>
<url-pattern>*.shtml</url-pattern>
</servlet-mapping>
3、这一步很重要!!!在apache-tomcat-7.0.72\conf目录下web.xml 中搜索<extension>shtml</extension>
将代码
<mime-mapping>
<extension>shtml</extension>
<mime-type>text/x-server-parsed-html</mime-type>
</mime-mapping>
改成
<mime-mapping>
<extension>html</extension>
<mime-type>text/html</mime-type>
</mime-mapping>
<mime-mapping>
<extension>shtml</extension>
<mime-type>text/html</mime-type>
</mime-mapping>
对,你没看错,将一份变成两份了,并且mime-type变成了text/html了
然后重启tomcat就可以在html文件中使用include指令了
指令格式: <!--#include virtual="../include/ad.html" -->
注意 : <!--#include 这些字符中间是没有空格的
另外就是WEB-INF下面的xml中不要又这样的配置:
<jsp-config>
<jsp-property-group>
<url-pattern>*.html</url-pattern>
<trim-directive-whitespaces>true</trim-directive-whitespaces>
</jsp-property-group>
</jsp-config>
不然的话ssi是不起作用的,就是因为这个原因。。。。搞了好几天。。。。