request.getScheme() 的使用

request.getSchema()能夠返回當前頁面使用的協議,好比,通常應用返回http;SSL返回https;服務器

request.getServerName()能夠返回當前頁面所在的服務器的名字;code

request.getServerPort()能夠返回當前頁面所在的服務器使用的端口,就是80;get

request.getContextPath()能夠返回當前頁面所在的應用的名字;request

String path = request.getContextPath();
String projectName = path.replace("/", "");
String basePath = request.getScheme()+"://" + 
request.getServerName()+":"+request.getServerPort()+path+"/";
相關文章
相關標籤/搜索