获取项目根路径

Javascript

<script type="text/javascript">
	// http://localhost:8080/wego/goods/list.jsp
	 
	//获取当前网址,如: http://localhost
	let curWwwPath=window.document.location.href;

	//获取主机地址之后的目录,如: wego/goods/list.jsp
	let pathName=window.document.location.pathname;
	let pos=curWwwPath.indexOf(pathName);

	//获取主机地址,如:http://localhost:8080
	let localhostPaht=curWwwPath.substring(0,pos);

	//获取带"/"的项目名,如:/wego
	let projectName=pathName.substring(0,pathName.substr(1).indexOf('/')+1);
</script>

获取项目根路径

function getCtxPath(){
    let pathName=window.document.location.pathname;
    let ctxPath=pathName.substring(0,pathName.substring(1).indexOf('/')+2);
    return ctxPath;
}

thymeleaf

<script th:inline="javascript" type="text/javascript">
    var ctxPath  = [[@{/}]];
    var ctxPath = /*[[@{/}]]*/'';
    var ctxPath=[[${#httpServletRequest.getContextPath()}]];
</script>

你可能感兴趣的:(SpringBoot,#,thymeleaf,项目路径,根路径,javascript)