1.获取服务器IP、端口等
2015-10-19 19:49
225 查看
[b]比如,页面内部有一个连接,完整的路径应该是 http://192.168.0.1:8080/myblog/authen/login.do 其中http://server/是服务器的基本路径,myblog是当前应用程序的名字,那么,我的根路径应该是那么http://localhost:80/myblog/。 [/b]
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
<base href=" <%=basePath%>">
这个语句是用来拼装当前网页的相对路径的。
request.getSchema()可以返回当前页面使用的协议,就是上面例子中的“http”
request.getServerName()可以返回当前页面所在的服务器的名字,就是上面例子中的“localhost"
request.getServerPort()可以返回当前页面所在的服务器使用的端口,就是8080,
request.getContextPath()可以返回当前页面所在的应用的名字,就是上面例子中的myblog
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
<base href=" <%=basePath%>">
这个语句是用来拼装当前网页的相对路径的。
request.getSchema()可以返回当前页面使用的协议,就是上面例子中的“http”
request.getServerName()可以返回当前页面所在的服务器的名字,就是上面例子中的“localhost"
request.getServerPort()可以返回当前页面所在的服务器使用的端口,就是8080,
request.getContextPath()可以返回当前页面所在的应用的名字,就是上面例子中的myblog
相关文章推荐
- 识别、检测、跟踪、分割、显著性、重识别
- [LeetCode] Convert Sorted List to Binary Search Tree
- java关键字之break与continue的区别(简单明了的小例子)
- solr 从零学习开始
- Python下异步IO和协程简介
- 51nod 1289 大鱼吃小鱼 (栈_STL)
- 第20章——广播
- 详解设计模式六大原则
- [sicily]1817. 校歌手大奖赛
- protobuf源码解析
- 最小生成树
- 机器视觉算法提纲
- curator使用
- 环境光
- 《代码阅读方法与实践之读书笔记之二》
- C语言的传值与传址调用
- linux下卸载mysql
- Java中子类是否可以继承父类的static变量和方法而呈现多态特性
- Mybatis系列之实战篇(中)
- qcom_vuforia环境搭建