欢迎访问昆山宝鼎软件有限公司网站! 设为首页 | 网站地图 | XML | RSS订阅 | 宝鼎邮箱 | 后台管理


新闻资讯

MENU

软件开发知识

Context privileged=true 历史代码 图纸加密 里处理SSI的办法 在公司的历史代码里

点击: 次  来源:宝鼎软件 时间:2017-05-31

原文出处: hengyunabc

最近tomcat进级版本时,碰着了ssi理会的问题,记录下办理的进程,尚有tomcat ssi设置的要点。

tomcat 设置SSI的两种方法

Tomcat有两种方法支持SSI:Servlet和Filter。

SSIServlet

通过Servlet,org.apache.catalina.ssi.SSIServlet,默认处理惩罚”*.shtml”的URL。

设置方法:

修改tomcat的 conf/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>

SSIFilter

通过Filter,org.apache.catalina.ssi.SSIFilter,默认处理惩罚”*.shtml”的URL。

设置方法:

修改tomcat的 conf/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>

留意事项

留意:两种设置方法最好不要同时打开,除非很清楚是奈何设置的。

别的,在Tomcat的conf/context.xml里要设置privileged=”true”,不然有些SSI特性不能生效。

<Context privileged="true">

汗青代码里处理惩罚SSI的步伐

在公司的汗青代码里,在一个民众的jar包里通过自界说一个EnhancedSSIServlet,软件开发,担任了Tomcat的org.apache.catalina.ssi.SSIServlet来实现SSI成果的。

@WebServlet(name="ssi",
            initParams={@WebInitParam(name="buffered", value="1"), @WebInitParam(name="debug", value="0"),
                        @WebInitParam(name="expires", value="666"), @WebInitParam(name="isVirtualWebappRelative", value="0"),
                        @WebInitParam(name="inputEncoding", value="UTF-8"), @WebInitParam(name="outputEncoding", value="UTF-8") },
            loadOnStartup=1, urlPatterns={"*.shtml"}, asyncSupported=true)
public class EnhancedSSIServlet extends SSIServlet {

个中@WebServlet是Servlet3.0类型里的,所以利用到web-common的web项目标web.xml文件都要设置为3.0版本以上,譬喻:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee

http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">

</web-app>

Tomcat是启动Web应用时,会扫描所有@WebServlet的类,并初始化。

所以在利用到汗青代码的项目都只能利用Tomcat处事器,而且不能在tomcat的conf/web.xml里打开SSI相关的设置。

Tomcat版本进级的问题

Tomcat版本从7.0.57进级到7.0.59进程中,呈现了无法理会SSI include指令的错误:

SEVERE: #include--Couldn't include file: /pages/test/intelFilter.shtml
java.io.IOException: Couldn't get context for path: /pages/test/intelFilter.shtml
    at org.apache.catalina.ssi.SSIServletExternalResolver.getServletContextAndPathFromVirtualPath(SSIServletExternalResolver.java:422)
    at org.apache.catalina.ssi.SSIServletExternalResolver.getServletContextAndPath(SSIServletExternalResolver.java:465)
    at org.apache.catalina.ssi.SSIServletExternalResolver.getFileText(SSIServletExternalResolver.java:522)
    at org.apache.catalina.ssi.SSIMediator.getFileText(SSIMediator.java:161)
    at org.apache.catalina.ssi.SSIInclude.process(SSIInclude.java:50)
    at org.apache.catalina.ssi.SSIProcessor.process(SSIProcessor.java:159)
    at com.test.webcommon.servlet.EnhancedSSIServlet.processSSI(EnhancedSSIServlet.java:72)
    at org.apache.catalina.ssi.SSIServlet.requestHandler(SSIServlet.java:181)
    at org.apache.catalina.ssi.SSIServlet.doPost(SSIServlet.java:137)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:646)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:748)
    at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:604)
    at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:543)
    at org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:954)
    at org.apache.jsp.pages.lottery.jczq.index_jsp._jspService(index_jsp.java:107)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)

仔细查察源代码后,发明不能处理惩罚的include指令代码如下:

<!--#include virtual="/pages/test/intelFilter.shtml"-->