繁体   English   中英

如何从tomcat服务器中已部署的WAR文件中获取完整的URL

[英]How to get the full URL from deployed WAR file in a tomcat server

在服务器上部署我的战争应用程序时,我想获得它的完整URL。 假设我的应用程序war文件是“ test.war”,而tomcat安装在“ http:// localhost:8080 / ”上。

我想要的是从这个war文件中的Java代码获取“ http:// localhost:8080 / test / ”值,因为我必须将它们传递给其他服务。

我正在使用maven构建war文件,因此也欢迎任何特定于Maven的解决方案。

网址:“ http:// localhost:8080 /

网址:“ http:// localhost:8080 / test /

Uri:java代码中的“ / test /”

String uri = request.getContextPath();

请求是类HttpServletRequest
部署服务器tomcat时,如果文件.war的名称为ROOT.war-> URL为http:// localhost:8080 /
使用文件abc.war- > URL是http:// localhost:8080 / abc / ---> abc是上下文路径

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM