---
title: ThymeLeafでjavascriptにcontextPathを設定する
tags: []
categories: ["Programming", "Java", "org", "thymeleaf"]
date: 2012-09-25T08:03:34Z
updated: 2012-09-25T08:03:34Z
---

ThymeLeafでJSPの`${pageContext.request.contextPath}`、`request.getContextPath()`、`<c:url>`相当の結果をjavascriptに設定する方法

    <script type="text/javascript" th:inline="javascript">
    <!--
      var foo = {}; // namespace
      foo.CONTEXT_ROOT = /*[[${#httpServletRequest.contextPath}]]*/ '';
    //-->
    </script>

[http://www.thymeleaf.org/doc/Tutorial%20-%20Using%20Thymeleaf%2020120910.pdf][1] の20ページ目と50ページ目を参考


  [1]: http://www.thymeleaf.org/doc/Tutorial%20-%20Using%20Thymeleaf%2020120910.pdf
