找了個前端模板,多個HTML中有重復的部分,一改都改,所以對其進行重構,將重復的部分拿出來
看了很多方法,最簡單的是jQuery,但是在我這沒起作用,后來發現一個配置tomcat的ssi,讓服務器幫我們完成這件事。
1、打開apache-tomcat\conf\web.xml 配置文件
2、去掉文件298行左右關於ssi配置的注釋,具體去掉注釋的代碼如下:
<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> <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> <load-on-startup>4</load-on-startup> </servlet>
3、去掉文件405行左右關於ssi配置的注釋,加上(支持html引入)具體代碼如下:
<servlet-mapping> <servlet-name>ssi</servlet-name> <url-pattern>*.shtml</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>ssi</servlet-name> <url-pattern>*.html</url-pattern> </servlet-mapping>
修改context.xml文件
1、打開apache-tomcat-6.0.29\conf\context.xml配置文件
2、在文件19行Context節點中加入privileged=”true” 加入完之后的配置如下:
<Context privileged="true"> <!-- Default set of monitored resources --> <WatchedResource>WEB-INF/web.xml</WatchedResource> <!-- Uncomment this to disable session persistence across Tomcat restarts --> <!-- <Manager pathname="" /> --> <!-- Uncomment this to enable Comet connection tacking (provides events on session expiration as well as webapp lifecycle) --> <!-- <Valve className="org.apache.catalina.valves.CometConnectionManagerValve" /> --> </Context>
修改完后再打開看一眼修改成功沒有
具體行數找不到的,Ctrl F搜一下
前端引入
<div id="indexhtml"> <!--#include file="index.html"--> </div>
參考:https://blog.csdn.net/sanyuedexuanlv/article/details/27324783
https://my.oschina.net/u/1756499/blog/483403
