歡迎訪問昆山寶鼎軟件有限公司網站! 設為首頁 | 網站地圖 | 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"-->
排列三305组选前后关系 江西快三4分钟 河北排列七开奖走势图 群英会遗漏号码任二 比亚迪股票 时时彩后一6码 湖北十一选五分布走势图 福建22选5走势图大星彩票网 p2p网贷理财平台哪个好式服务平台怎么样 江西快3走势图 新快赢481稳赚不赔方案