关于jsp 获得当前绝对路径的方法

方法1)

  request.getRequestURL();

方法2)

     request.getScheme()+"://"+request.getServerName()+":"

    +request.getServerPort()+request.getContextPath()+request.getServletPath();

    其中 

  getScheme()                     http
  getServerName()               localhost
  getServerPort()                 8080
  request.getContextPath()   /Struts2_0300_Path

      request.getServletPath()    /path.jsp

两者输出均为 http://localhost:8080/Struts2_0300_Path/path.jsp

若只想获取其中的一部分路径 则只能用第二种方法

原文地址:https://www.cnblogs.com/kkkkkk/p/5428575.html