Tomcat7下配置SSI(解决中文乱码问题)
web.xml 取消SSI注释
1 <servlet>
2 <servlet-name>ssi</servlet-name>
3 <servlet-class>
4 org.apache.catalina.ssi.SSIServlet
5 </servlet-class>
6 <init-param>
7 <param-name>buffered</param-name>
8 <param-value>1</param-value>
9 </init-param>
10 <init-param>
11 <param-name>debug</param-name>
12 <param-value>0</param-value>
13 </init-param>
14 <init-param>
15 <param-name>expires</param-name>
16 <param-value>666</param-value>
17 </init-param>
18 <init-param>
19 <param-name>isVirtualWebappRelative</param-name>
20 <param-value>0</param-value>
21 </init-param>
22 <init-param>
23 <param-name>inputEncoding</param-name>
24 <param-value>utf-8</param-value>
25 </init-param>
26 <init-param>
27 <param-name>outputEncoding</param-name>
28 <param-value>utf-8</param-value>
29 </init-param>
30 <load-on-startup>4</load-on-startup>
31 </servlet>
1 <servlet-mapping>
2 <servlet-name>ssi</servlet-name>
3 <url-pattern>*.shtml</url-pattern>
4 </servlet-mapping>
*第一段中需要加上解析中文编码
1 <init-param>
2 <param-name>inputEncoding</param-name>
3 <param-value>utf-8</param-value>
4 </init-param>
5 <init-param>
6 <param-name>outputEncoding</param-name>
7 <param-value>utf-8</param-value>
8 </init-param>
context.xml 为 Context 加上 privileged="true" 属性 例如:<Context privileged="true">
1 <Context privileged="true">
2
3 <!-- Default set of monitored resources -->
4 <WatchedResource>WEB-INF/web.xml</WatchedResource>
5
6 <!-- Uncomment this to disable session persistence across Tomcat restarts -->
7 <!--
8 <Manager pathname="" />
9 -->
10
11 <!-- Uncomment this to enable Comet connection tacking (provides events
12 on session expiration as well as webapp lifecycle) -->
13 <!--
14 <Valve className="org.apache.catalina.valves.CometConnectionManagerValve" />
15 -->
16 </Context>
2
3 <!-- Default set of monitored resources -->
4 <WatchedResource>WEB-INF/web.xml</WatchedResource>
5
6 <!-- Uncomment this to disable session persistence across Tomcat restarts -->
7 <!--
8 <Manager pathname="" />
9 -->
10
11 <!-- Uncomment this to enable Comet connection tacking (provides events
12 on session expiration as well as webapp lifecycle) -->
13 <!--
14 <Valve className="org.apache.catalina.valves.CometConnectionManagerValve" />
15 -->
16 </Context>
不多说直接上代码
SSI用法:
必须为*.shtml页面加载 例如:index.shtml
1 <!-- header -->
2 <!--#include virtual="header.html" -->
3 <!-- news -->
4 <!--#include virtual="news.html" -->
5 <!-- guild -->
6 <!--#include virtual="guild.html" -->
7 <!-- service -->
8 <!--#include virtual="service.html" -->
9 <!-- friendLink -->
10 <!--#include virtual="friendLink.html" -->
11 <!-- footer -->
2 <!--#include virtual="header.html" -->
3 <!-- news -->
4 <!--#include virtual="news.html" -->
5 <!-- guild -->
6 <!--#include virtual="guild.html" -->
7 <!-- service -->
8 <!--#include virtual="service.html" -->
9 <!-- friendLink -->
10 <!--#include virtual="friendLink.html" -->
11 <!-- footer -->
12 <!--#include virtual="footer.html" -->