美文网首页
2018-11-16

2018-11-16

作者: 崛誓悻詈 | 来源:发表于2018-11-16 16:15 被阅读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()  项目名称

相关文章

网友评论

      本文标题:2018-11-16

      本文链接:https://www.haomeiwen.com/subject/fyvmfqtx.html