如何使用 Tomcat 在其 URL 中隐藏应用程序上下文? [英] How to hide application context in its URL with Tomcat?

查看:50
本文介绍了如何使用 Tomcat 在其 URL 中隐藏应用程序上下文?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有许多应用程序在 Tomcat 中运行.每个人都有自己的背景.我使用 Apache HTTP Server 和 mod_jk 将它们全部连接到不同的域名(请参阅此问题的更多详细信息:How to mount使用 mod_jk 的上下文引用的 Tomcat 应用程序?).工作正常,但是当应用程序生成它们的网页时,所有 URL 仍然有它们的上下文:

  1. http://www.example.com/ 转到 http://www.example.com:8080/my-context/
  2. http://www.example.com:8080/my-context/ 生成网页
  3. 网页包含 URL /my-context/some-page.jsf

我想在第三步中看到 /some-page.jsf.需要注意的是,我无法更改应用程序内部结构.它们由第三方提供.我能做的就是配置Tomcat或Apache HTTP Server.

解决方案

这有点复杂,但您可以使用 URL 重写器,例如 tuckey重写出站 URL,删除/my-context 前缀(出站 URL"是指在您的 web 应用程序中生成的 URL).在 http://urlrewritefilter 上查看该元素的文档.googlecode.com/svn/trunk/src/doc/manual/3.2/index.html.

要使 tuckey 与您的 web 应用程序配合使用,您需要向应用程序的 web.xml 添加声明.从技术上讲,这意味着修改应用程序",但它是微创的.如果由于某种原因(不知道为什么)您甚至无法触摸 web.xml,我似乎记得有一种方法可以在 Tomcat 中的 web 应用程序上从外部强加过滤器(不是阀门),但这已经很远了.

I have a number of applications running in Tomcat. Every one has its own context. I hooked them all to different domain names with Apache HTTP Server and mod_jk (see more details at this question: How to mount context-referenced Tomcat application with mod_jk?). Works fine, but when applications generate their web pages all URLs still have their contexts:

  1. http://www.example.com/ goes to http://www.example.com:8080/my-context/
  2. http://www.example.com:8080/my-context/ produces a web page
  3. The web page contains URL /my-context/some-page.jsf

I would like to see /some-page.jsf in the third step. What's important to notice is that I can't change application internals. They are provided by third parties. All I can do is to configure Tomcat or Apache HTTP Server.

解决方案

This is getting a bit complicated, but you can use a URL rewriter such as tuckey to rewrite outbound URLs, removing the /my-context prefix (by "outbound URLs" I mean URLs being generated inside your webapp(s)). Check out the documentation for the element at http://urlrewritefilter.googlecode.com/svn/trunk/src/doc/manual/3.2/index.html.

To make tuckey work with your webapp, you would need to add declarations to your apps' web.xml. Technically this means "modifying the applications", but it is minimally invasive. If you can't even touch the web.xml for some reason (not sure why), I seem to recall a way to externally impose a filter (not a valve) on a webapp in Tomcat, but that's going pretty far.

这篇关于如何使用 Tomcat 在其 URL 中隐藏应用程序上下文?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆