您的位置:首页 > 其它

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: