Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/374.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在thymeleaf中获取内容路径?_Java_Jquery_Spring Boot_Thymeleaf - Fatal编程技术网

Java 如何在thymeleaf中获取内容路径?

Java 如何在thymeleaf中获取内容路径?,java,jquery,spring-boot,thymeleaf,Java,Jquery,Spring Boot,Thymeleaf,我有一个使用springboot 1.5.10、EclipseIDE和Thymeleaf的项目 在一些页面中,我在jquery中有如下重定向: 例如:在选择选项中 $('#month').on('change', function() { window.location = "/dashboard/operation/month/" + month; }) 在一个按钮里 $('#bFind').click(function() { var newUrl = "/dashboard

我有一个使用springboot 1.5.10、EclipseIDE和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);
});
这两种重定向在我的控制器中都非常有效

网址如下:

但问题是,当我在ApacheTomcat9.0.6中创建一个war项目来部署它时,我必须给出一个要部署的名称

部署后,url为:

它打破了东西

mywebapp可以是另一个名称

因此,我一直在寻找添加上下文路径:

我找到的主要信息是:

但当我把它添加到may header.html文件时,我总是没有定义

<meta name="ctx" th:content="${#httpServletRequest.getContextPath()}" />

也许有另一种方法可以做到这一点,并正确添加上下文路径

有什么建议吗

谢谢

也许可以试试这个:

如果上下文是localhost:8080,它将输出

但如果您的上下文是localhost:8080/mywebapp,它将输出


我认为这是客户端的问题,而不是服务器端的问题,在开始时使用“/”设置位置始终返回服务器根目录(localhost:8080/)