thymeleaf js 获取项目路径 contextPath的方法

  1. 1.thymeleaf 标签:
th:onclick="@{'location.href=\'' + ${#httpServletRequest.getContextPath()} + '/xxxx\'}"

  1. 2.javascript中引用

 

  1. 3 单独在js文件中获取

 

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 + '/';  
	} 

 

你可能感兴趣的:(thymeleaf js 获取项目路径 contextPath的方法)