2018-11-16

2018-11-16  本文已影响0人  崛誓悻詈

JavaScript技术问题:

在HTML页面中获取项目的根据经(使用thymeleaf前端框架):

<body>

<a th:href="${#httpServletRequest.getScheme() + '://' + #httpServletRequest.getServerName() + ':' + #request.getServerPort() + #request.getContextPath() + '/'} "   id="contextPath"></a>

</body>

<javascript type="text/javascript">

//thymeleaf的语法,获取项目根路径

//var ctxPath ="[[@{/}]]";


//获取项目根据经

var ctxPath = $("#contextPath").attr("href");

</javascript>

java技术加强:

String schema = httpServletRequest.getScheme()  获取正确的协议

String serverName = httpServletRequest.getServerName()  获取服务名称

int serverPort = request.getServerPort()  获取服务的端口号

String contentPath = request.getContextPath()  项目名称

上一篇 下一篇

猜你喜欢

热点阅读