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/

转载于:https://www.cnblogs.com/aipan/p/5113797.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值