[英]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.