zoukankan      html  css  js  c++  java
  • Java获取服务器网址

    StringBuffer url1 = request.getRequestURL();
    String tempContextUrl1 = url1.delete(url1.length() - request.getRequestURI().length(), url1.length()).append("/").toString();
    System.out.println("------1>"+tempContextUrl1);


    StringBuffer url = request.getRequestURL();
    String tempContextUrl = url.delete(url.length() - request.getRequestURI().length(), url.length()).append(request.getContextPath()).append("/").toString();
    System.out.println("------2>"+tempContextUrl);

    System.out.println("------3>"+request.getRemoteHost()+request.getContextPath());



    System.out.println("-----ServletPath---" + request.getServletPath());
    System.out.println("-----ContextPath---" + request.getContextPath());
    System.out.println("-----referer---" + request.getHeader("referer"));
    System.out.println("-----host---" + request.getHeader("host"));
    System.out.println("-----RequestURI---" + request.getRequestURI());
    System.out.println("-----RequestURL---" + request.getRequestURL());
    System.out.println("-----ServerName---" + request.getServerName());
    System.out.println("-----ServerPort---" + request.getServerPort());
    String realPath1 = "http://"+ request.getServerName()+ ":"+ request.getServerPort()+ request.getContextPath()+ request.getServletPath().substring(0,request.getServletPath().lastIndexOf("/") + 1);
    System.out.println("web URL 路径:" + realPath1);

    http://10.5.14.66:8101/f1print/exceltemp/001/BarCodePrint.pdf
    ------1>http://localhost:8080/
    ------2>http://localhost:8080/yxlis/
    ------3>0:0:0:0:0:0:0:1/yxlis
    -----ServletPath---/case/LLBarcodePrintSave.jsp
    -----ContextPath---/yxlis
    -----referer---http://localhost:8080/yxlis/case/LLBarcodePrintMain.jsp
    -----host---localhost:8080
    -----RequestURI---/yxlis/case/LLBarcodePrintSave.jsp
    -----RequestURL---http://localhost:8080/yxlis/case/LLBarcodePrintSave.jsp
    -----ServerName---localhost
    -----ServerPort---8080
    web URL 路径:http://localhost:8080/yxlis/case/

  • 相关阅读:
    机器学习知识体系
    重新指派usb转串口模块在linux系统中的设备调用名称
    ROS 进阶学习笔记(13)
    121. 买卖股票的最佳时机
    SpringBoot | 集成Java Mail
    SpringBoot | 遇坑总结 | JPA
    测试 | 单元测试工具 | JUnit | 参数化
    测试 | 单元测试工具 | JUnit
    JSP | 基础 | 连接数据库
    Mysql | 总结 | 常用的查询语句(单表查询)
  • 原文地址:https://www.cnblogs.com/aipan/p/5113797.html
Copyright © 2011-2022 走看看