IT民工窝棚qbq.blog.chinaunix.net

长期从事高难度、高压力、高伤害、耗体力、耗精力、耗时间、低工资、低补助、低趣味、随叫随到的工作 ---- 这就是程序员,三高三低三耗

  • 博客访问: 18921603
  • 博文数量: 808
  • 博客积分: 12163
  • 博客等级: 上将
  • 技术积分: 8290
  • 用 户 组: 普通用户
  • 注册时间: 2007-12-04 20:59
文章分类

全部博文(808)

微信关注

IT168企业级官微



微信号:IT168qiye



系统架构师大会



微信号:SACC2013

订阅
热词专题
Tomcat 6 配置SSI 2012-08-08 14:29:10

分类: Java

官方详细介绍

官方文档里有个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 不乱码了===================

经过上面的配置,包含文件:
<!--#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)
    ...

阅读(7396742) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~
评论热议
请登录后评论。

登录 注册