简体   繁体   English

如何获取百里香的内容路径?

[英]How to get content path in thymeleaf?

I have a project using springboot 1.5.10, eclipse IDE and Thymeleaf. 我有一个使用springboot 1.5.10,eclipse IDE和Thymeleaf的项目。

In several pages I have redirections like this in jquery: 在几页中,我在jquery中有这样的重定向:

eg: In a Select Option 例如:在选择选项中

$('#month').on('change', function() {

    window.location = "/dashboard/operation/month/" + month;
})

eg: In a Button 例如:按钮中

$('#bFind').click(function() {
  var newUrl = "/dashboard/operation/month/";
  newUrl += month;
  $('a').attr('href', newUrl);
});

Both redirect works great defined in my Controller. 两种重定向都可以在我的控制器中很好地定义。

The urls are: http://localhost:8080/dashboard/operation/month/01 网址为: http:// localhost:8080 / dashboard / operation / month / 01

But the problem is when I create a war project to deploy it in my apache tomcat 9.0.6 I have to give a name to deploy. 但是问题是当我创建一个战争项目以将其部署到apache tomcat 9.0.6中时,我必须给出要部署的名称。

Once you have deployed the url is: http://localhost:8080/mywebapp/dashboard/operation/month/01 部署后,URL为: http:// localhost:8080 / mywebapp / dashboard / operation / month / 01

and it breaks the stuff... 它破坏了东西...

mywebapp could be another name. mywebapp可能是另一个名称。

So I have been looking for add context path: 所以我一直在寻找添加上下文路径:

The main info I found is: 我发现的主要信息是:

What is the Syntax to get Thymeleaf ${pageContext.request.contextPath} 获取Thymeleaf $ {pageContext.request.contextPath}的语法是什么

But when I add this to may header.html file I get always undefined 但是,当我将其添加到may header.html文件中时,我总是无法定义

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

Maybe is there is another way to do this and add the context path correctly. 也许还有另一种方法可以正确地添加上下文路径。

Any suggestions? 有什么建议么?

Thanks 谢谢

https://www.thymeleaf.org/doc/articles/standardurlsyntax.html https://www.thymeleaf.org/doc/articles/standardurlsyntax.html

Maybe try this: 也许试试这个:

<meta name="ctx" th:content="@{/}" />

If the context is localhost:8080, it will output 如果上下文是localhost:8080,它将输出

<meta name="ctx" content="/" />

But if your context is localhost:8080/mywebapp it will output 但是,如果您的上下文是localhost:8080 / mywebapp,它将输出

<meta name="ctx" content="/mywebapp/" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM