jsp如何在没有javascript的情况下干净地获取基本url [英] jsp how to get base url cleanly without javascript
问题描述
我试图获取基本URL(例如: https://stackoverflow.com/),而不使用JavaScript.但是似乎有很多方法可以将它与 https://stackoverflow.com/questions/ask 分开,所以我想知道最干净的方法是什么(或者是否有首选方法).
I'm trying to get the base url (for example: https://stackoverflow.com/) without using javascript. But there seem to be a lot of ways to split it off from https://stackoverflow.com/questions/ask so I was wondering what the cleanest way was (or if there's a preferred method).
jstl函数可能会解决问题,但是我希望它尽可能地动态,因此,如果/questions/部分要更改为/question/,则不必更改它. /p>
jstl functions would probably do the trick, but I'd like it to be as dynamically as possible, so I wouldn't have to change it if the /questions/ part was to change to let's say /question/.
${pageContext.request.scheme}://${pageContext.request.serverName}:${pageContext.request.serverPort}
这是一个选择,但是有点冗长.
Is an option, but it's well a bit verbose.
感谢您的任何投入.
推荐答案
在功能标签库.
${fn:replace(pageContext.request.requestURL, pageContext.request.requestURI, '')}
这篇关于jsp如何在没有javascript的情况下干净地获取基本url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!