JSP中path与basePath的区别
2017-10-23 10:57
281 查看
在一般的JSP页面中,我们经常可以看到如下代码:<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%><%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";Date time = new Date();%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html> <head> <base href="<%=basePath%>"> <title>My JSP 'demo1.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"><meta http-equiv="cache-control" content="no-cache"><meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"><meta http-equiv="description" content="This is my page"><!--<link rel="stylesheet" type="text/css" href="styles.css">--><script type="text/javascript" src="<%=path%>/ext/ext-all.js"></script><link rel="stylesheet" type="text/css" href="ext/resources/css/ext-all.css"><script type="text/javascript" src="<%=path%>/demo1.js?time=<%=time%>"></script> <script type="text/javascript"> Ext.onReady(function () { Ext.Msg.alert('<%=path%>'); Ext.Msg.alert('<%=basePath%>'); }); </script> </head> <body> This is my JSP page. <br> </body></html> 以上代码先后弹出以下内容: /rlsm ----path的值 http://localhost:8080/rlsm/ -----basePath的值 -----------------------------------------------------------------------------------------------------------------------------知识点: ① request.getScheme() 返回当前页面使用的协议;默认返回http,SSL时返回https; ② request.getServerName() 返回当前页面所在的服务器的名字; ③request.getServerPort() 返回当前页面所在的服务器使用的端口,就是项目在服务器上发布的端口,或者在本地tomcat容器运行时发布的端口,我用的是8080; ④request.getContextPath() 返回当前页面所在的应用的名字;
相关文章推荐
- JSP中path与basePath的区别
- (转)jsp base path作用
- 解决JSP路径问题的方法(jsp文件开头path, basePath作用)
- JSP使用include指令出现“Duplicate local variable basePath”错误提示
- jsp中的basePath
- JSP里的basePath
- JSP中<base href="<%=basePath%>">作用
- 解决JSP页面中路径问题的方法(jsp文件开头path, basePath作用)
- 解决JSP路径问题的方法(jsp文件开头path, basePath作用)
- JSP中<base href="<%=basePath%>">作用
- jsp中的basePath和path
- jsp文件开头path, basePath作用
- JSP中<base href="<%=basePath%>">作用
- 解决JSP路径问题的方法(jsp文件开头path, basePath作用)
- JSP中<base href="<%=basePath%>">的作用
- JSP里的basePath
- jsp中的basePath和path
- 解决JSP路径问题的方法(jsp文件开头path, basePath作用)
- jsp路径basepath的作用
- JSP路径basePath的作用