• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录

Gredswsh的技术生活

Java,Python,Go,SCI_NUM
  • 联系
  • 订阅
  • 管理

公告

View Post

String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getSer

这其实就是 获得应用的根url,比如说你的应用的根路径是 http://localhost:8080,那么你列出的代码就是为basePath赋值为 http://localhost:8080。
具体点:
1、request.getScheme() 返回协议的名称 http,和后面的"://" 拼起来就成了 http://
2、request.getServerName() 这是获取你的服务器的名称,如果你的应用部署在本机那么其就返回localhost或者127.0.0.1 ,这2个是等价的
3、request.getServerPort() 是你应用使用的端口,比如8080或者80 等等

上面3点的结果拼起来就构成了你应用的根路径或者说是根url

这个是我自己获取程序地址的方法:

request.setAttribute("basePath", request.getScheme() + "://"             + request.getServerName() + ":" + request.getServerPort()             + request.getContextPath() + "/");

basepath的 属性为程序地址

转载请注明文章出处:http://www.cnblogs.com/gredswsh   Gredswsh  专栏

posted on 2014-07-04 09:40  fxcl  阅读(647)  评论(0)    收藏  举报

刷新页面返回顶部
 
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3