1

I have a project using springboot 1.5.10, eclipse IDE and Thymeleaf.

In several pages I have redirections like this in 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

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.

Once you have deployed the url is: http://localhost:8080/mywebapp/dashboard/operation/month/01

and it breaks the stuff...

mywebapp could be another name.

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}

But when I add this to may header.html file I get always undefined

<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

davisoski
  • 727
  • 2
  • 14
  • 41
  • I think it is the problem with your clientside, not serverside, setting location with '/' at the beginning always return the server root (localhost:8080/) – cdxf Apr 03 '18 at 13:09

1 Answers1

1

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

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

But if your context is localhost:8080/mywebapp it will output

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

cdxf
  • 5,501
  • 11
  • 50
  • 65