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

1
  • I think it is the problem with your clientside, not serverside, setting location with '/' at the beginning always return the server root (localhost:8080/) Commented Apr 3, 2018 at 13:09

1 Answer 1

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/" />

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.