JavaWeb之basePath
来源:互联网 发布:风火轮打单软件 编辑:程序博客网 时间:2024/05/21 22:28
问:有这样的语句
:
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
<base href="<%=basePath%>">
答:这个语句是用来拼装当前网页的相对路径的。
<base href="...">是用来表明当前页面的相对路径所使用的根路径的。
比如,页面内部有一个连接,完整的路径应该是 http://localhost:80/myblog/authen/login.do
其中http://server/是服务器的基本路径,myblog是当前应用程序的名字,那么,我的根路径应该是那么http://localhost:80/myblog/。
有了这个<base ... >以后,我的页面内容的连接,我不想写全路径,我只要写 authen/login.do就可以了。服务器会自动把<base ...>指定的路径和页面内的相对路径拼装起来,组成完整路径。
如果没有这个<base...>,那么我页面的连链接就必须写全路径,否则服务器会找不到。
request.getSchema()可以返回当前页面使用的协议,就是上面例子中的“http”
request.getServerName()可以返回当前页面所在的服务器的名字,就是上面例子中的“localhost"
request.getServerPort()可以返回当前页面所在的服务器使用的端口,就是80,
request.getContextPath()可以返回当前页面所在的应用的名字,就是上面例子中的myblog
这四个拼装起来,就是当前应用的跟路径了
转自http://blog.csdn.net/huaishitou/article/details/41745473
阅读全文
0 0
- JavaWeb之basePath
- JSP之basePath
- javaweb 项目中 求 basePath中的方法
- basePath
- basePath
- basePath
- basePath
- Struts2基础之三:URL路径的跳转 和basePath
- basepath 变量
- 关于BasePath
- JSP BASEPATH
- JavaWeb之文件上传
- javaWeb资料之二
- JavaWeb 之 Servlet入门
- JavaWeb 之 servletConfig,servletContext
- JavaWeb 之 HttpServletResponse
- JavaWeb 之 HttpServletRequest
- javaweb之http协议
- android 发送邮件--实现 send email for android
- hibernate4.x 报错org.hibernate.TransientPropertyValueException: Not-null property references a
- 过山车 (匈牙利算法)
- JQuery3.1.1源码解读(五)【select 函数】
- Marching Cubes
- JavaWeb之basePath
- gerrit自动设置reviewer
- Fragment和Activity两种沉浸式状态栏的实现
- ORM系列之二:EF(4) Model First
- 三月不开单,开单吃三月说的是你吗?
- 如何领养微信聊天机器人
- linux中的man命令总结
- 日记20171109ONE
- poj1144 Network(割顶)