How to hide application context in its URL with Tomcat?

主宰稳场 提交于 2020-01-02 09:28:56

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/5165781/how-to-hide-application-context-in-its-url-with-tomcat

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!