js页面基本代码解释
2017-10-07 11:21
204 查看
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
这个语句是用来拼接当前网页的相对路径的。
一、用这个base,服务器就可以动态的将指定路径和页面的相对路径拼装起来,形成完整的路径。
1.request.getSchema();可以返回当前页面所使用的协议,就是"http"
2.request.getServerName();返回当前页面所在服务器的名字,就是上面例子中的"localhost"
3.request.getServerPort();返回当前页面所在服务器的端口号,就是上面例子中的"8085"
4.request.getContextPath();返回当前页面所在的应用的名字,就是上面例子中的"Info_System"
当前页面路径是:http://localhost:80/Info_System/uploadAttachs/attachs_list.jsp
根据上面的介绍,那么我在当前页面中有跳转为:
<li>
<a href="<%=basePath%>user/user_info.jsp" class="informatio
4000
n_off">
</a>
</li>
就应该这样写。
二、<base herf="...">用来表明当前页面的相对路径所使用的根路径,也就是项目名称(只能放在<head>中)
如:<base href="<%=basePath%>">
则:<a href="http://www.baidu.com/xxx.htm"></a>,你现在就只需要写<a
href="xxx.htm"></a>
什么是根路径:
比如,页面内部有一个连接,完整的路径应该是 http://localhost:8085/Info_System/user/user_info.jsp
其中http://server/是服务器的基本路径,Info_System是当前应用程序的名字,那么,我的根路径应该是http://localhost:8085/Info_System/。
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
这个语句是用来拼接当前网页的相对路径的。
一、用这个base,服务器就可以动态的将指定路径和页面的相对路径拼装起来,形成完整的路径。
1.request.getSchema();可以返回当前页面所使用的协议,就是"http"
2.request.getServerName();返回当前页面所在服务器的名字,就是上面例子中的"localhost"
3.request.getServerPort();返回当前页面所在服务器的端口号,就是上面例子中的"8085"
4.request.getContextPath();返回当前页面所在的应用的名字,就是上面例子中的"Info_System"
当前页面路径是:http://localhost:80/Info_System/uploadAttachs/attachs_list.jsp
根据上面的介绍,那么我在当前页面中有跳转为:
<li>
<a href="<%=basePath%>user/user_info.jsp" class="informatio
4000
n_off">
</a>
</li>
就应该这样写。
二、<base herf="...">用来表明当前页面的相对路径所使用的根路径,也就是项目名称(只能放在<head>中)
如:<base href="<%=basePath%>">
则:<a href="http://www.baidu.com/xxx.htm"></a>,你现在就只需要写<a
href="xxx.htm"></a>
什么是根路径:
比如,页面内部有一个连接,完整的路径应该是 http://localhost:8085/Info_System/user/user_info.jsp
其中http://server/是服务器的基本路径,Info_System是当前应用程序的名字,那么,我的根路径应该是http://localhost:8085/Info_System/。
相关文章推荐
- JS调用页面表格导出excel示例代码
- yii2 页面上编写js代码,并注册到页面底部
- JS刷新框架外页面七种实现代码
- js禁止页面回退,刷新,右键代码
- c++ 中extern的基本解释说明(VC代码)
- js 弹出提示信息,并跳转指定页面代码分享
- js实现页面打印功能实例代码(附去页眉页脚功能代码)
- 页面正在载入(js代码)
- js统计页面的来访次数实现代码
- JS动态添加的div点击跳转到另一页面实现代码
- django js实现部分页面刷新的示例代码
- 始终在页面底部的层js实现代码
- 调用 ajax调用出来的页面的 js代码
- js形成页面的一种遮罩效果实例代码
- 用js判断页面是否加载完成实现代码
- JS和JQUERY获取页面大小,滚动条位置,元素位置(示例代码)
- js实现单一html页面两套css切换代码
- JS实现页面内跳转的简单代码
- Js 本页面传值实现代码