gpt4 book ai didi

tomcat - 如何在 Tomcat 6 中定义应用程序的上下文路径?

转载 作者:行者123 更新时间:2023-11-28 22:32:18 25 4
gpt4 key购买 nike

应用程序部署在上下文路径“/environame/appname”上的 Tomcat6 上。

<Context
...
path="/environame/appname"
...
</Context>

但我无法使用以下 URL 访问我的应用程序:

http://localhost:8080/environame/appname

我必须在“environame”和“appname”之间使用下划线而不是斜线。

http://localhost:8080/environame_appname

Tomcat 5 的工作方式有所不同。
如果是 Tomcat 5,URL 中将没有下划线:

http://localhost:8080/environame/appname

在“environame”和“appname”之间使用斜线而不是下划线访问我的应用程序或 Tomcat 6 的配置时,我应该更改什么?

更新:

path The context path of this web application, which is matched against the beginning of each request URI to select the appropriate web application for processing. All of the context paths within a particular Host must be unique. If you specify a context path of an empty string (""), you are defining the default web application for this Host, which will process all requests not assigned to other Contexts.

The value of this field must not be set except when statically defining a Context in server.xml, as it will be inferred from the filenames used for either the .xml context file or the docBase.

http://tomcat.apache.org/tomcat-5.5-doc/config/context.html

我们将上下文 xml 文件存储到 $CATALINA_HOME/conf/Catalina/localhost/environame_appname.xml 文件中。Tomcat 5.0.28 使用 Context 元素的路径属性。
Tomcat 6 使用上下文 xml 文件的名称。
是否可以更改配置以使用路径属性而不是 xontext xml 文件的名称?

答案:
有一个错误bug#46713

If a path attribute is set inside the context tag in context xml's it is ignored. Instead the path is set to "/" + . While it nice that even pathes with '/' can be encoded in the file name by replacing '/' with '#' it is very confusing that an existing path attribute is simply ignored.

因此,我只需要将我的上下文 xml 文件重命名为 environame#appname.xml。

最佳答案

很久以前(我认为是 tomcat 4)可以部署一个名称为 environame_appname.war 的 war 存档,并且 tomcat 可以通过 url environame/appname/使它可用...我不确定这是否仍然存在有效(并且还没有时间测试它)。 Tomcat 用斜杠和下划线做了一些替换。

实现您的目标的另一种方法是使用 apache 和 mod_proxy、mod_proxy_ajp(或 mod_proxy_html)和 mod_rewrite。然后你可以在tomcat中定义两个应用程序(app01和app02),定义一个将请求转发到/app01(resp/app02)到你的tomcat的代理规则和一个重写规则将请求重写到/env01/app到/app01和/env02/app02 到/app02。

关于tomcat - 如何在 Tomcat 6 中定义应用程序的上下文路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10043151/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com