• java web中获取各种路径


    一、获取项目路径:

    1)

    String path = request.getContextPath() :// /TestMyEclipse
    String basePath = request.getScheme()+"://" +request.getServerName()+ ":" +request.getServerPort()+ path+"/";
    http://127.0.0.1:8080/TestMyEclipse/

    2)

    路径是:<c:out value="${pageContext.request.contextPath }"></c:out>

    打印结果是:/springMVC  是项目根路径

    二、获取url地址:

    获取页面的url地址:
    String url = request.getScheme()+"://" +request.getServerName()+ ":" +request.getServerPort();
    url += request.getContextPath();
    url += request.getServletPath() + "?" + request.getQueryString();
    打印出来是:
    http://localhost:8080/BBS/articleFlat.jsp?pageNo=2

    还有两个:
    System.out.println(request.getRequestURI());
    System.out.println(request.getRequestURL()):
    分别打印出来是:
    /BBS/articleFlat.jsp
    http://localhost:8080/BBS/articleFlat.jsp

    所以上面的获取url地址,包括参数可以这么写了:
    String url = request.getRequestURL() + "?" + request.getQueryString();

    ----------------------------------------------------------------------------------------------------------------------------------------------------

  • 相关阅读:
    黄金作为货币的本质
    万有引力和做功。
    Arp攻击实战
    Android SDK下载项的说明
    宇宙、事象
    事件视界
    微积分
    金融的三大基础货币,股票,期货。
    pos机的热敏纸尺寸
    去除text历史记录
  • 原文地址:https://www.cnblogs.com/tenWood/p/6338126.html
Copyright © 2020-2023  润新知