jsp頁面獲取完整的路徑

  1. <% 
  2. String path = request.getContextPath(); 
  3. String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"
  4. %> 
  5. request.getSchema()可以返回當前頁面使用的協議,http 或是 https;

  6. request.getServerName()可以返回當前頁面所在的服務器的名字;如果你的應用部署在本機那麼其就返回localhost或者127.0.0.1 ,這兩個是等價的;

  7. request.getServerPort()可以返回當前頁面所在的服務器使用的端口,就是8083;

  8. request.getContextPath()可以返回當前頁面所在的應用的名字;

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章