java - Tomcat篡改404未找到错误,返回500

标签 java tomcat wicket

ObHumor:显然找不到我的“未找到”页面。 :-)

我有一个 Wicket 应用程序,它有一个自定义的 404 Not Found 页面。当我们在 Glassfish 下运行时曾经工作正常,当我使用 Jetty 和 Start.java 时它继续工作正常。

但是当在 Tomcat 7.0.19 下运行时,应用程序从不显示其 404 页面 - Tomcat 似乎“吃掉”了错误的请求,并向客户端返回 500。我在日志中看到以下内容:

0:0:0:0:0:0:0:1%0 - - [30/Sep/2011:16:35:57 -0400] "GET /bad-link HTTP/1.1" 500 5

我的 web.xml 中有以下内容:

<error-page>
    <error-code>404</error-code>
    <location>/404</location>
</error-page>

事实上,如果我直接访问该页面 (/404),我会看到我的 404 页面。但是如果我请求“/bad-link”,我会得到 Tomcat 的 500 响应。

这是我的 tomcat server.xml:

<?xml version='1.0' encoding='utf-8'?>
<Server port="8005" shutdown="SHUTDOWN">
  <!-- Security listener. Documentation at /docs/config/listeners.html
  <Listener className="org.apache.catalina.security.SecurityListener" />
  -->
  <!--APR library loader. Documentation at /docs/apr.html -->
  <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
  <!--Initialize Jasper prior to webapps are loaded. Documentation at /docs/jasper-howto.html -->
  <Listener className="org.apache.catalina.core.JasperListener" />
  <!-- Prevent memory leaks due to use of particular java/javax APIs-->
  <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
  <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
  <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />

  <GlobalNamingResources>
    <!-- Editable user database that can also be used by
         UserDatabaseRealm to authenticate users
    -->
    <Resource name="UserDatabase" auth="Container"
              type="org.apache.catalina.UserDatabase"
              description="User database that can be updated and saved"
              factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
              pathname="conf/tomcat-users.xml" />
  </GlobalNamingResources>

  <Service name="Catalina">

    <!--The connectors can use a shared executor, you can define one or more named thread pools-->
    <!--
    <Executor name="tomcatThreadPool" namePrefix="catalina-exec-" 
        maxThreads="150" minSpareThreads="4"/>
    -->


    <!-- A "Connector" represents an endpoint by which requests are received
         and responses are returned. Documentation at :
         Java HTTP Connector: /docs/config/http.html (blocking & non-blocking)
         Java AJP  Connector: /docs/config/ajp.html
         APR (HTTP/AJP) Connector: /docs/apr.html
         Define a non-SSL HTTP/1.1 Connector on port 8080
    -->
    <Connector port="8080" protocol="HTTP/1.1" 
               URIEncoding="UTF-8"
               connectionTimeout="20000" 
               redirectPort="8443"/>
    <!-- A "Connector" using the shared thread pool-->
    <!--
    <Connector executor="tomcatThreadPool"
               port="8080" protocol="HTTP/1.1" 
               connectionTimeout="20000" 
               redirectPort="8443" />
    -->           
    <!-- Define a SSL HTTP/1.1 Connector on port 8443
         This connector uses the JSSE configuration, when using APR, the 
         connector should be using the OpenSSL style configuration
         described in the APR documentation -->
    <!--
    <Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
               maxThreads="150" scheme="https" secure="true"
               clientAuth="false" sslProtocol="TLS" />
    -->

    <!-- Define an AJP 1.3 Connector on port 8009 -->
    <Connector port="8009" protocol="AJP/1.3" redirectPort="8443"
               URIEncoding="UTF-8"/>


    <!-- An Engine represents the entry point (within Catalina) that processes
         every request.  The Engine implementation for Tomcat stand alone
         analyzes the HTTP headers included with the request, and passes them
         on to the appropriate Host (virtual host).
         Documentation at /docs/config/engine.html -->

    <!-- You should set jvmRoute to support load-balancing via AJP ie :
    <Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">         
    --> 
    <Engine name="Catalina" defaultHost="localhost">

      <!--For clustering, please take a look at documentation at:
          /docs/cluster-howto.html  (simple how to)
          /docs/config/cluster.html (reference documentation) -->
      <!--
      <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
      -->        

      <!-- Use the LockOutRealm to prevent attempts to guess user passwords
           via a brute-force attack -->
      <Realm className="org.apache.catalina.realm.LockOutRealm">
        <!-- This Realm uses the UserDatabase configured in the global JNDI
             resources under the key "UserDatabase".  Any edits
             that are performed against this UserDatabase are immediately
             available for use by the Realm.  -->
        <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
               resourceName="UserDatabase"/>
      </Realm>

      <Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">

        <!-- SingleSignOn valve, share authentication between web applications
             Documentation at: /docs/config/valve.html -->
        <!--
        <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
        -->

        <!-- Access log processes all example.
             Documentation at: /docs/config/valve.html
             Note: The pattern used is equivalent to using pattern="common" -->
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"  
               prefix="localhost_access_log." suffix=".txt"
               pattern="%h %l %u %t &quot;%r&quot; %s %b" resolveHosts="false"/>

      </Host>
    </Engine>
  </Service>
</Server>

除了我添加的以下行之外,我的 catalina.properties 是普通的:

org.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH=true

这允许 %2F 编码的斜杠出现在 URL 中。

编辑:以防万一:我的应用程序安装在根上下文中(即部署为 ROOT.war)。

最佳答案

您是否也将此添加到您的 web.xml 中?

<filter-mapping>
   <filter-name>wicket.filter.my</filter-name>
   <url-pattern>/*</url-pattern>
   <dispatcher>REQUEST</dispatcher>
   <dispatcher>ERROR</dispatcher>
</filter-mapping>

关于java - Tomcat篡改404未找到错误,返回500,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7615882/

相关文章:

java - 将空列表作为参数传递给 JPA 查询会引发错误

java - 合并两个图像

jsp - 我的 servlet 中的编码问题

java - 为什么我的 Wicket 面板在更改默认模型后不重新渲染?

java - Swagger-ui - 列表参数编码

java - intellij idea中tomcat运行配置启动时间长

spring - 一段时间不活动后tomcat连接中断

java - Wicket 标签中的嵌套链接

java - 使用 Maven 加载 wicket 示例项目

c# - 从 PDF 中仅提取粗体文本的最佳方法