【问题标题】:Lift webapp has directory and resource with the same name, but gives 302Lift webapp 具有同名的目录和资源,但给出 302
【发布时间】:2011-07-31 12:23:23
【问题描述】:

我将 example.war 部署到 Tomcat 6.0.32(撰写本文时最新),部署的 webapp 包含以下内容:

$ find example | egrep -v "WEB-INF/lib|WEB-INF/classes"
example
example/_items.html
example/_share_link.html
example/all_items.html
example/images
example/images/ajax-loader.gif
example/index.html
example/item
example/item/star.html
example/item.html
example/js
example/js/c-jquery-1.4.2.js
example/js/c-jquery-ui-1.8.2.js
example/js/jquery-1.4.2.js
example/js/jquery-1.4.4.min.js
example/js/jquery-ui-1.8.2.js
example/js/jquery-ui-1.8.8.custom.min.js
example/js/jquery.blockUI.js
example/META-INF
example/META-INF/MANIFEST.MF
example/search.html
example/static
example/static/index.html
example/templates-hidden
example/templates-hidden/default.html
example/templates-hidden/wizard-all.html
example/WEB-INF
example/WEB-INF/web.xml

特别注意:

example/item
example/item/star.html
example/item.html

我尝试请求上述资源:

$ telnet localhost 8080
Trying ::1...
Connected to localhost.
Escape character is '^]'.
GET /example/item HTTP/1.0

HTTP/1.1 302 Moved Temporarily
Server: Apache-Coyote/1.1
Location: http://localhost:8080/example/item/
Date: Thu, 07 Apr 2011 08:24:39 GMT
Connection: close

Connection closed by foreign host.

服务器让我试试/example/item/

$ telnet localhost 8080
Trying ::1...
Connected to localhost.
Escape character is '^]'.
GET /example/item/ HTTP/1.0

HTTP/1.1 404 Not Found
Server: Apache-Coyote/1.1
Set-Cookie: JSESSIONID=6D97AD3A8F77697146163946B1BBBB64; Path=/example
Expires: Thu, 7 Apr 2011 08:24:58 UTC
Cache-Control: no-cache, private, no-store
Pragma: no-cache
Date: Thu, 07 Apr 2011 08:24:58 GMT
X-Lift-Version: 2.3
Content-Type: text/html;charset=utf-8
Content-Length: 106
Connection: close

<!DOCTYPE html>
<html> <body>The Requested URL /example/item/ was not found on this server</body> </html>  
  Connection closed by foreign host.

这不是我所期望的。对/example/item 的第一个请求(没有尾部斜杠)应该可以工作——此时Lift Web 框架接管并呈现我的项目,使用star.html 作为模板。这适用于 Jetty 6.1.22 和 Resin 4.0.16,但不适用于 Tomcat。

我缺少一些特殊的配置吗?在这种情况下,servlet 规范中是否有指示正确行为的内容?

我使用的示例代码可以在这里找到: https://github.com/dpp/simply_lift/tree/master/samples/shopwithme

我在这里提出了原始问题: https://groups.google.com/forum/?fromgroups#!topic/liftweb/7QlFud1ieOU

注意这个问题不是关于 Lift 或其渲染管道——而是关于 Tomcat,以及为什么它的行为与 Jetty 和 Resin 的不同。


更新:这是经典的“斜线”问题,已在此处提交错误报告:https://issues.apache.org/bugzilla/show_bug.cgi?id=32424

【问题讨论】:

    标签: tomcat servlets jetty lift


    【解决方案1】:

    有人回答了这个问题,但这个问题的措辞完全不同,这就是为什么我要按原样保留我自己的问题(对于那些使用不同搜索词的用户):

    Where does Tomcat append / to directory paths?

    简而言之,看看这个类:

    http://svn.apache.org/repos/asf/tomcat/tc6.0.x/tags/TOMCAT_6_0_26/java/org/apache/tomcat/util/http/mapper/Mapper.java

    ...然后在该类中找到详细说明“默认 servlet”的注释——它被称为“规则 7”,根据许多人的说法,这是一个错误:https://issues.apache.org/bugzilla/show_bug.cgi?id=32424

    根据一位开发人员的评论,在可预见的情况下,它将在 Tomcat 中保持不变:

    未指定行为 任何地方,但想法是在 物理文件夹或根目录的情况 在上下文中,结尾的 '/' 不是 相关的。由于这会导致反复 路径解析问题(这使得 servlet 就像我们的默认 servlet 不必要地更复杂),我们总是 向 servlet 提供培训 '/' 在所有情况下。这也是最 高效,所以这就是 目前正在实施的 用过。

    我很遗憾它会阻止你 使用Tomcat,但没有什么 我这里改一下。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-02-22
      • 2016-06-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-25
      • 1970-01-01
      相关资源
      最近更新 更多