这是eclipse的
这是idea的
打开 Run —> Edit Configurations —> Deployment,在右侧有个 Application context,这里的值也是和路径有关的
Application context 中填写的值会直接加到 localhost:8080 的后面,以之前的例子来说,本来 DemoServlet 这个 servlet 类的访问路径是 localhost:8080/DemoServlet,如果在 Application context 中填写的是 /haha,那么其访问路径就变成了 localhost:8080/haha/DemoServlet,对于 jsp 页面的访问路径也是同样的道理
springboot在application.properties配置项目根路径访问名
注意版本问题
spring-boot 2.0以下是server.context-path 和 server.servlet-path,
spring-boot 2.0及以上是server.servlet.context-path 和 server.servlet.path