如何获得百里香的内容路径?
我有一个使用springboot 1.5.10,eclipse IDE和Thymeleaf的项目。
在几个页面中,我在jquery中有这样的重定向:
例如:在选择选项中
$('#month').on('change', function() { window.location = "/dashboard/operation/month/" + month; })
例如:在按钮中
$('#bFind').click(function() { var newUrl = "/dashboard/operation/month/"; newUrl += month; $('a').attr('href', newUrl); });
两个重定向都在我的控制器中定义很好。
url为: http:// localhost:8080 / dashboard / operation / month / 01
但问题是当我创建一个war项目在我的apache tomcat 9.0.6中部署它时,我必须给出一个名称来部署。
一旦你部署了url: http:// localhost:8080 / mywebapp / dashboard / operation / month / 01
它打破了东西……
mywebapp可能是另一个名字。
所以我一直在寻找添加上下文路径:
我发现的主要信息是:
什么是获取Thymeleaf $ {pageContext.request.contextPath}的语法
但是,当我将此添加到may header.html文件时,我总是未定义
也许是有另一种方法来做到这一点并正确添加上下文路径。
有什么建议?
谢谢
https://www.thymeleaf.org/doc/articles/standardurlsyntax.html
也许试试这个:
如果上下文是localhost:8080,它将输出
但是如果您的上下文是localhost:8080 / mywebapp,它将输出