request常用方法
阿新 • • 發佈:2021-01-07
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()可以返回當前頁面所在的專案的名字 “/ 專案名
”;
上例程式碼的輸出結果如下: