0

Initially, I deployed my Spring Boot project using the embedded Tomcat Server. The URL was the following one: http://localhost:8080/home.

I have finally used an external Tomcat Server and when I deployed my Spring project the final URL was the following one: http://localhost:8080/MyApp/home.

Due to that all my resources paths are modified.

For example:

CSS (located in src/main/resources/static/css/*)

   Before :  <link rel="stylesheet" href="/css/login.css">

The only solution that I found is to modify the path to :

   After : <link rel="stylesheet" href="/MyApp/css/login.css">

This is not very maintainable and I would like to know if there is a better solution?

dur
  • 15,689
  • 25
  • 79
  • 125
  • You could change the root context for external Tomcat to `/` or change root context for embedded Tomcat to `/MyApp`. – dur Sep 04 '21 at 18:09
  • 1
    If you change to `href="css/login.css"` without the "/" ? – pleft Sep 04 '21 at 19:26
  • Thank you to both of you. Pleft effectively, when I removed the "/" the path is correctly interpreted as : `href="/MyApp/css/login.css"` – Azrahell Sep 04 '21 at 20:18
  • As a general rule you should either use relative URI paths as pleft suggested or prepend the context path to all URIs in your template (e.g. `${contextPath}` in JSPs). – Piotr P. Karwasz Sep 04 '21 at 20:23
  • As @pleft said you should use related path. Also you can read [difference between relative path and absolute path](https://stackoverflow.com/questions/21306512/difference-between-relative-path-and-absolute-path-in-javascript) – mohammad_1m2 Sep 04 '21 at 20:25
  • 1
    I adapted the code from `` to``. It's a mistake from my side because i'm using thymeleaf for my pages – Azrahell Sep 04 '21 at 20:30

0 Answers0