Tomcat 6 配置SSI

2019阿里云双11返场狂欢继续,
地址https://www.aliyun.com/1111/2019/home

推荐:Tomcat工程配置SSI

[网上有的是修改$CATALINA_HOME/conf/web.xml来做到这一点,可我不想每个工程都有ssi的功能,所以想把它移植进单个应用。   做法如下:   1. copy必要的jar包: $CATALINA_

官方详细介绍

官方文档里有个bug
追查代码才发现的
isVirtualWebappRelative - Should "virtual" SSI directive paths be interpreted as relative to the context root, instead of the server root? (0=false, 1=true) Default 0 (false).
这里源码用的是
isVirtualWebappRelative = Boolean.parseBoolean(getServletConfig().getInitParameter("isVirtualWebappRelative"));

所以:0和1都是false,只有配置文件里写成true,这里才能取到true


否则如果你要用虚拟路径
而且不在一个应用下
这样写<!--#include virtual="/abc/include.html" -->是怎么也找不到这个文件的


简单翻译:

1.去掉tomcat6中conf/web.xml关于ssi的注释

===================================(1)===========================================
<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>
<load-on-startup>4</load-on-startup>
</servlet>

=====================================(2)==========================================
<servlet-mapping>
<servlet-name>ssi</servlet-name>
<url-pattern>*.shtml</url-pattern>
</servlet-mapping>
=================================tomcat6重启出错=================================

java.lang.SecurityException: Servlet of class org.apache.catalina.ssi.SSIServlet is

privileged and cannot be loaded by this web application

==================================修改context.xml==================================

在标签<Context>里加入 privileged="true"
变为:
<Context privileged="true">

==========================tomcat6重启 以运行包含页面但乱码=======================

修改conf/web.xml
在conf/web.xml中的ssi servlet配置中添加以下初始配置:


<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>

修改为:
<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>

===========================重启tomcat6 仍乱码===================



=====================过一两分钟再重启tomcat6 不乱码了===================

经过上面的配置,

推荐:Tomcat中SSI的配置

[1.简介:   SSI全称(Server Side Includes)是在HTML静态页面中使用的指令,当页面在服务端执行的时候是可以进行服务端解析的。这种方式可以让我们在� ...]

包含文件:
<!--#include file="include.html" -->
<!--#include virtual="include.html" -->
注意:在tomcat中,在包含命令中,一定要加双引号,否则会出现异常

例如:不加双引号<!--#include virtual=include.html -->,会出现如下异常
SEVERE: Servlet.service() for servlet ssi threw exception
java.lang.NullPointerException
    at org.apache.catalina.ssi.SSIMediator.substituteVariables(SSIMediator.java:211)
    ...

推荐:关于TOMCAT 配置 SSI的问题

[我按照论坛里面所有的方法  一步一步的设置  就是搞不定 : 1 我的 tomcat 版本是 6.0.18 。 删除tomcat  conf 目录中的web.xml文件中 所有的关于 ssi的注释  在 tomcat

相关推荐