JSP獲取頁面URL地址

<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>
<!DOCTYPE html>
<html>
<head>
<base href="<%=basePath%>">

1、request.getSchema()可以返回當前頁面使用的協議,http 或是 https等

2、request.getServerName()可以返回當前頁面所在的服務器的名字,域名或者ip地址;

3、request.getServerPort()可以返回當前頁面所在的服務器使用的端口;

4、request.getContextPath()可以返回當前頁面所在的應用的名字,相當於工程名;

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章