Tomcat 和上下文路径
我在 Netbeans 中创建了一个 Web 应用程序,并将该应用程序打包在一个名为“aa-bb.war”的文件中。当我在 netbeans 中运行该项目时,我可以通过“localhost:8080/aa/bb”访问它。这一切都很好。
不过,将 .war 文件移动到标准 tomcat 安装中会给我带来问题。当我将 .war 放入“webapp”目录时,它会分解为“webapp/aa-bb”,但我真正想要的是“webapp/aa/bb”(注意之间的“-”与“/” “aa”和“bb”)...所以 bb 应该位于“aa”的子目录中。
我对此的理解是因为tomcat使用.war的文件名来创建分解的目录,因此由于war被称为“aa-bb”,所以它显然使用了连字符。我的“context.xml”文件确实具有正确的路径“aa/bb”,但我读到 Tomcat 5+ 将忽略 .war 中指定的上下文路径并根据文件名创建路径。
我怎样才能强制tomcat使用子目录(它可能看起来像结果url中的一个小差异(“aa-bb”与“aa/bb”),但它实际上是一个大问题,原因是我不明白现在就开始(只会让事情变得复杂)。
I created a web application in Netbeans, and it packages the application in a file called "aa-bb.war". When I run the project in netbeans, I can access it at "localhost:8080/aa/bb". This is all good.
Moving the .war file into a standard tomcat installation though, gives me problems. When I drop the .war into the "webapp" directory, it gets exploded into "webapp/aa-bb", but what I really want is "webapp/aa/bb" (note the "-" vs "/" in between "aa" and "bb")... so bb should be in a subdirectory of "aa".
My understanding of this is because tomcat uses the filename of the .war to create the exploded dir, and so since the war is called "aa-bb", it obviously uses the hyphen. My "context.xml" file does have the correct path "aa/bb", but I've read that Tomcat 5+ will ignore the context path specified in the .war and create a path based on filename instead.
How can I force tomcat to use a subdirectory (it may seem like a small difference in the resulting url ("aa-bb" vs "aa/bb"), but it actually is a big problem for reasons that I won't get into right now (just complicates things).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
tomcat的标准部署结构是所有应用程序都处于第一级层次结构。您放入应用程序文件夹中的任何 context.war 文件最终都可以通过 http://host/context 进行访问。我很确定你不能强制你提到的子目录 aa/bb 但你可以通过以下方式欺骗实现:(1) 制作应用程序 aa.war ,(2) 在你的 aa 应用程序中创建一个名为 bb 的目录,其中包含所有内容您的 jsps,以及 (3) 如果您有 servlet 或过滤器,那么还要更改它们到 bb/servlet 的映射。
The standard deployment structure of tomcat is that all applications are at the first level hierarchy. Any context.war file you drop in your applications folder would eventually become accessible via http://host/context. I'm pretty sure that you can't force the subdirectory aa/bb you mention but you could trick the implementation by: (1) making application aa.war , (2) creating a directory within your aa application called bb that has all your jsps, and (3) if you have servlets or filters then also change the mapping of those to bb/servlet.
你有什么选择?我不知道 Tomcat 最近忽略了
path=""
。将 apache 放在前面,并使用
mod_redirect
或mod_proxy
将 Apache 中的 aa/bb 请求集中到 Tomcat 中的 aa-bb。在 Web 应用程序旁边使用 UrlRewriteFilter,具体取决于您使用的 Web 框架(如果有? )。调用您的 web 应用程序 aa.war,然后告诉 UrlRewriteFilter 将应用程序内对 /bb/ 的请求集中到 / 。
What options do you have? I didn't know that Tomcat disregards the
path=""
lately.Put apache in front and use
mod_redirect
ormod_proxy
to funnel requests for aa/bb in Apache to aa-bb in Tomcat.Use the UrlRewriteFilter iside the webapp, depending on whatever web framework you're using(if any?). Call your webapp aa.war, then tell UrlRewriteFilter to funnel requests for /bb/ inside the app to just / instead.