request.getSchema() 可以返回當前頁面使用的協議,http 或是 https;
request.getServerName() 可以返回當前頁面所在的服務器的名字;
request.getServerPort() 可以返回當前頁面所在的服務器使用的端口,就是80;
request.getContextPath() 可以返回當前頁面所在的應用的名字;
在程序中的應用如下:
- String path = request.getContextPath();
- String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
- <base href="<%=basePath%>">