日常学习记录(Thymeleaf)
// http://localhost:8080/shiyi/test
<script th:inline="javascript" type="text/javascript">
// 1.
var ctxPath = [[@{/}]];
console.log(ctxPath); // 结果: /shiyi/
// 2.
var ctxPath = [[${#servletContext.contextPath}]];
console.log(ctxPath); // 结果: /shiyi
// 3.
var ctxPath = [[${#request.getContextPath()}]];
console.log(ctxPath); // 结果: /shiyi
// 4.
var ctxPath = [[${#httpServletRequest.getContextPath()}]];
console.log(ctxPath); // 结果: /shiyi
</script>
参考资料: https://www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf.html#web-context-objects