1. 程式人生 > 其它 >request常用方法

request常用方法

技術標籤:Java學習java

request 的常用方法:

<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
	System.out.println(path);
	System.out.println(basePath);
%>

request.getSchema()可以返回當前頁面使用的協議,“http

” 或是“https” ;

request.getServerName()可以返回當前頁面所在的伺服器的名字“localhost” ;

request.getServerPort()可以返回當前頁面所在的伺服器使用的埠,就是 “8080”;

request.getContextPath()可以返回當前頁面所在的專案的名字 “/ 專案名”;

上例程式碼的輸出結果如下:
在這裡插入圖片描述