您的位置:首页 > Web前端 > JavaScript

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()      返回当前页面所在的应用的名字; 

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