tomcat下如何才能运行shtml文件?

4/29/2009来源:JSP技巧人气:9587

我们知道,需要运行shtml,必须在web服务器上配置好ssi。
下面是ssi在tomcat5.*上的配置方法:

打开tomcat配置文件:conf/web.xml
1、去掉下面servlet前的注释

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

改成

<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映射的注释

/*<servlet-mapping>
<servlet-name>ssi</servlet-name>
<url-pattern>*.shtml</url-pattern>
</servlet-mapping>
*/

改成

<servlet-mapping>
<servlet-name>ssi</servlet-name>
<url-pattern>*.shtml</url-pattern>
</servlet-mapping>

3、在server\lib目录中找到servlets-ssi.renametojar文件,改成 servlets-ssi.jar

4、重启tomcat

5、新建一个shtml文件测试一下

<HTML>
<HEAD>
<TITLE>shtml测试</TITLE>
</HEAD>
<BODY>
<!–#echo var=”DATE_LOCAL” –>
<!–#include virtual=”hello.jsp”–>
</BODY>
</HTML>

执行ok!!!