th:onclick="@{'location.href=\'' + ${#httpServletRequest.getContextPath()} + '/xxxx\'}"
2.javascript中引用
<script type="text/javascript" th:inline="javascript">
/*<![CDATA[*/
ctxPath = /*[[@{/}]]*/ '';
/*]]>*/
</script>
function getRootPath() {
var pathName = window.location.pathname.substring(1);
var webName = pathName == '' ? '' : pathName.substring(0, pathName.indexOf('/'));
return window.location.protocol + '//' + window.location.host + '/' + webName + '/';
}