jsp how to get base url cleanly without javascript

╄→гoц情女王★ 提交于 2019-12-24 02:19:11

问题


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 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.

Any input is appreciated.


回答1:


Use the following with a little help of JSTL functions taglib.

${fn:replace(pageContext.request.requestURL, pageContext.request.requestURI, '')}


来源:https://stackoverflow.com/questions/4278445/jsp-how-to-get-base-url-cleanly-without-javascript

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!