【发布时间】:2018-09-12 19:42:15
【问题描述】:
我有一个项目使用 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);
});
在我的控制器中定义的两个重定向都很好。
网址是: http://localhost:8080/dashboard/operation/month/01
但问题是,当我创建一个战争项目以将其部署到我的 apache tomcat 9.0.6 中时,我必须提供一个名称才能部署。
部署后,网址为: http://localhost:8080/mywebapp/dashboard/operation/month/01
它破坏了东西......
mywebapp 可以是另一个名称。
所以我一直在寻找添加上下文路径:
我找到的主要信息是:
What is the Syntax to get Thymeleaf ${pageContext.request.contextPath}
但是当我将它添加到可能的 header.html 文件时,我总是不确定
<meta name="ctx" th:content="${#httpServletRequest.getContextPath()}" />
也许还有另一种方法可以做到这一点并正确添加上下文路径。
有什么建议吗?
谢谢
【问题讨论】:
-
我认为这是您的客户端的问题,而不是服务器端的问题,在开头使用“/”设置位置总是返回服务器根目录 (localhost:8080/)
标签: java jquery spring-boot thymeleaf