0

I would like to know if it possible to get the context path in my controller without set the value in application.properties

server.contextPath

When I create a war to deploy in an apache tomcat server I get something like this:

mywebapp-0.0.1-SNAPSHOT.war

so just simple I change name to "mywebapp" and deploy.

But if I want to change to "mywebapp2" and have two webapps running I need to change the value in server.contextPath.

I would like to do something like I do in thymeleaf:

How to get content path in thymeleaf?

where I get the context-path without worring about the name, but instead of thymeleaf in my java controller.

Thanks

davisoski
  • 727
  • 2
  • 14
  • 41

1 Answers1

2

Declare a formal parameter HttpServletRequest request in the handler method of your controller. Then call request.getContextPath.

Abhijit Sarkar
  • 21,927
  • 20
  • 110
  • 219