java web项目获取端口_web项目获取全路径、端口、项目名等

文章转自:https://blog.csdn.net/u010180031/article/details/52369537

在程序中我们一般这样使用。说到了这里,我们可以看看request常用的方法:

request.getSchema(),返回的是当前连接使用的协议,一般应用返回的是http、SSL返回的是https;

request.getServerName(),返回当前页面所在的服务器的名字;

request.getServerPort(),返回当前页面所在的服务器使用的端口,80;

request.getContextPath(),返回当前页面所在的应用的名字。

getContextPath()是jsp中获取路径的一种方式,那么获取到结果是什么呢?jsp其他获取路径的方式是怎样的呢?表示好奇,请听分解:

以访问的jsp为:http://localhost:8080/dmsd-itoo-exam-log-web/course/index.jsp,工程名为/dmsd-itoo-exam-log-web为例:

request.getContextPath(),得到工程名:/dmsd-itoo-exam-log-web;

request.getServletPath(),返回当前页面所在目录下全名称:/course/index.jsp;

request.getRequestURL(),返回IE地址栏地址:http://localhost:8080/dmsd-itoo-exam-log-web/course/index.jsp;

request.getRequestURI() ,返回包含工程名的当前页面全路径:/dmsd-itoo-exam-log-web/course/index.jsp。

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值