JSP创建时的<% String path = request.getContextPath();%>
来源:互联网 发布:js数组去重 编辑:程序博客网 时间:2024/05/16 06:01
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
这个语句用来拼装当前网页的相对路径。
比如,页面内有一个连接,完整的路径应该是 http://localhost:80/mytest/authen/login.jsp
其中http://localhost:80是服务器的基本路径,mytest是当前应用程序的名字,则根路径应该是那么http://localhost:80/mytest/。
有了这个 basePath 以后,我的页面内容的连接,我不想写全路径,我只要写 authen/login.do就可以了。服务器会自动把 <base ...>指定的路径和页面内的相对路径拼装起来,组成完整路径。
如果没有这个 basePath,那么我页面的连链接就必须写全路径,否则服务器会找不到。
request.getSchema()可以返回当前页面使用的协议,就是上面例子中的“http”
request.getServerName()可以返回当前页面所在的服务器的名字,就是上面例子中的“localhost"
request.getServerPort()可以返回当前页面所在的服务器使用的端口,就是80,
request.getContextPath()可以返回当前页面所在的应用的名字,就是上面例子中的mytest
这四个拼装起来,就是当前应用的跟路径了
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
这个语句用来拼装当前网页的相对路径。
比如,页面内有一个连接,完整的路径应该是 http://localhost:80/mytest/authen/login.jsp
其中http://localhost:80是服务器的基本路径,mytest是当前应用程序的名字,则根路径应该是那么http://localhost:80/mytest/。
有了这个 basePath 以后,我的页面内容的连接,我不想写全路径,我只要写 authen/login.do就可以了。服务器会自动把 <base ...>指定的路径和页面内的相对路径拼装起来,组成完整路径。
如果没有这个 basePath,那么我页面的连链接就必须写全路径,否则服务器会找不到。
request.getSchema()可以返回当前页面使用的协议,就是上面例子中的“http”
request.getServerName()可以返回当前页面所在的服务器的名字,就是上面例子中的“localhost"
request.getServerPort()可以返回当前页面所在的服务器使用的端口,就是80,
request.getContextPath()可以返回当前页面所在的应用的名字,就是上面例子中的mytest
这四个拼装起来,就是当前应用的跟路径了
0 0
- JSP创建时的<% String path = request.getContextPath();%>
- String path = request.getContextPath
- String path = request.getContextPath(); JSP中的相对Path的设置
- String path = request.getContextPath();JSP中的相对Path的设置
- String path = request.getContextPath(); JSP中的相对Path的设置
- JSP中语句<% String path = request.getContextPath(); String basePath...的含义
- jsp文件中<% String path = request.getContextPath(); %>语句的作用
- String path = request.getContextPath();获取应用的上下文路径。
- String path = request.getContextPath路径问题
- String Path = request.getContextPath()报错
- String path = request.getContextPath();这段什么用
- String path = request.getContextPath(....拼装当前网页的相对路径
- String path = request.getContextPath(拼装当前网页的相对路径 )
- String path = request.getContextPath(....拼装当前网页的相对路径
- String path = request.getContextPath(....拼装当前网页的相对路径
- 转发重定向用到的绝对路径 String path = request.getContextPath
- String path = request.getContextPath(....拼装当前网页的相对路径
- <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getSe
- 第六届蓝桥杯循环节长度
- 微信小程序学习笔记(二)
- jquery ajax 无刷新上传文件到servlet
- android 标准体重计算器
- 02-JZ2440裸机学习之MMU内存管理单元
- JSP创建时的<% String path = request.getContextPath();%>
- 用C语言完成对文件的定位和打印目录项以及所占簇号
- 积跬步,聚小流------html知识大纲归纳总结
- form表单 input标签以及其属性,datalist标签
- Git简明教程
- Callable与Future的介绍
- 数组中重复的数字:hash表-->unordered_map<>
- Service绑定(上)
- 面试题1