简体   繁体   English

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

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

I wanted to get the full URL of my war app when I deploy it on the server. 在服务器上部署我的战争应用程序时,我想获得它的完整URL。 Let say my application war file is "test.war" and my tomcat installation is on " http://localhost:8080/ ". 假设我的应用程序war文件是“ test.war”,而tomcat安装在“ http:// localhost:8080 / ”上。

What I want is to get the " http://localhost:8080/test/ " value from my Java code inside of this war file, since I have to pass them around to other services. 我想要的是从这个war文件中的Java代码获取“ http:// localhost:8080 / test / ”值,因为我必须将它们传递给其他服务。

I am using maven to build the war file, so any maven-specific solution is also welcome. 我正在使用maven构建war文件,因此也欢迎任何特定于Maven的解决方案。

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

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

Uri: "/test/" in java code Uri:java代码中的“ / test /”

String uri = request.getContextPath();

Request is class HttpServletRequest 请求是类HttpServletRequest
When deploy server tomcat if file .war with name is ROOT.war --> URL is http://localhost:8080/ 部署服务器tomcat时,如果文件.war的名称为ROOT.war-> URL为http:// localhost:8080 /
With file abc.war --> URL is http://localhost:8080/abc/ ---> abc is context path 使用文件abc.war- > URL是http:// localhost:8080 / abc / ---> abc是上下文路径

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

相关问题 无法获取tomcat以显示已部署的.war文件中的webapp - Cant get tomcat to show webapp from deployed .war file 如何从部署在同一tomcat中的另一个war文件重新配置war文件的log4j - How to reconfigure log4j of a war file from another war file deployed in same tomcat Tomcat使用war文件作为url部署到远程服务器 - Tomcat deploy to remote server with war file as url 如何在Spring Boot应用程序中启用HTTPS,该应用程序在Tomcat中作为WAR文件部署? - How to enable HTTPS in a Spring Boot application, deployed as WAR file in Tomcat? 无法在Tomcat管理器中启动已部署的War文件 - Deployed war file not starting in tomcat manager spring war文件部署到tomcat 9但没有正确重定向? - spring war file deployed to tomcat 9 but not redirecting properly? Tomcat 7:部署的war文件的缓存副本 - Tomcat 7: cached copy of war file deployed 如何在tomcat服务器中获取所有已部署的应用程序 - How to get all deployed application in tomcat server 来自部署在tomcat的WAR资源的JVM参数 - JVM argument from WAR resource deployed at tomcat 从部署到已运行的Tomcat 8实例的Spring Boot WAR文件内部获取Tomcat正在运行的端口 - Obtaining the port that Tomcat is running on from inside a Spring Boot WAR file deployed to an already running instance of Tomcat 8
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM