标签:style blog http color os java io strong 文件
tomcat官方文档
CAUTION - SSI directives can be used to execute programs external to the Tomcat JVM. If you are using the Java SecurityManager this will bypass your security policy configuration in
catalina.policy.
To use the SSI servlet, remove the XML comments from around the SSI servlet and servlet-mapping configuration in
$CATALINA_BASE/conf/web.xml
.To use the SSI filter, remove the XML comments from around the SSI filter and filter-mapping configuration in
$CATALINA_BASE/conf/web.xml
.Only Contexts which are marked as privileged may use SSI features (see the privileged property of the Context element).
让tomcat支持SSI有两种方式,一种是Servlet,另一种是Filter
基于Servlet方式:
在web.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>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> -->
和
<!-- <servlet-mapping> <servlet-name>ssi</servlet-name> <url-pattern>*.shtml</url-pattern> </servlet-mapping> -->去掉注释。
然后在context.xml中设置
<Context privileged="true">
Filter方式:
在web.xml找到
<!-- <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>false</param-value> </init-param> </filter> -->和
<!-- <filter-mapping> <filter-name>ssi</filter-name> <url-pattern>*.shtml</url-pattern> </filter-mapping> -->以及
<!-- <mime-mapping> <extension>shtml</extension> <mime-type>text/x-server-parsed-html</mime-type> </mime-mapping> -->同样去掉注释,也需要在context.xml文件中设置
<Context privileged="true">重启tomcat。
进行测试
index.shtml
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>ssi 示例</title>
</head>
<body>
ssi area <!--#include virtual="ssi.html" -->
<p>
footer <!--#include virtual="footer.html" --><p>
<p>
<!--#config timefmt="%D" -->
Me last modified <!--#echo var="LAST_MODIFIED" -->
</body>
</html>
footer.html<ul>
<li>index</li>
<li>about</li>
</ul>
ssi.html<p>this is ssi.html file</p><p>
<p>中文</p>
ssi.html file end
<p/>现在可以,http://localhost:8080/test/index.shtml 有结果了。
如果出现中文乱码,可以在servlet ssi或filter ssi中添加初始化参数
<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>参考文章:http://chenlb.iteye.com/blog/227184
标签:style blog http color os java io strong 文件
原文地址:http://www.cnblogs.com/naruto469/p/3938980.html