jsp內置對象request的常用方法

訪問頁面地址:http://localhost:8080/my/index.jsp

頁面主要代碼及註釋
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
/*
request.getScheme()可以返回當前頁面使用的協議;默認返回http,SSL時返回https;
request.getServerName()可以返回當前頁面所在的服務器的名字;
request.getServerPort()可以返回當前頁面所在的服務器使用的端口,就是項目在服務器上發佈的 端口,或者在本地tomcat容器運行時發佈的端口,我用的是8081;
request.getContextPath()可以返回當前頁面所在的應用的名字;
*/
%>

<p>
<%=path %>
<br>
<%=basePath %>
</p>


運行後的輸出結果
/my 
http://localhost:8080/my/ 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章