Get the server port number from tomcat without a request

前端 未结 12 1594
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-28 06:32

Is there any Tomcat API or configuration available which can tell an application (probably on startup), what port its running on without a request?

Imagine a scenari

12条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-28 07:26

    If you want to access an application on the same server instance, just omit the server part of the URL. Some examples what you can achieve. The current document is at http://example.com:8080/app2/doc.html

    • xxx.html becomes http://example.com:8080/app2/xxx.html
    • ../xxx.html becomes http://example.com:8080/xxx.html
    • ../xxx.html becomes http://example.com:8080/xxx.html
    • ../foo/xxx.html becomes http://example.com:8080/foo/xxx.html
    • ../../xxx.html becomes http://example.com:8080/xxx.html (there is no way to go beyond the root)
    • /xxx.html becomes http://example.com:8080/xxx.html This is probably what you look for.
    • //other.com/xxx.html becomes http://example.com:8080/xxx.html Useful if you want to keep "https:"

提交回复
热议问题