request.getContextPath()的功能
<%
String contextPath = request.getContextPath(); // 得到项目的名字
com.chint.until.SessionInfo sessionInfo = (com.chint.until.SessionInfo) session.getAttribute("sessionInfo");
%>
在JSP中有html、js、java这三种语言,其中的java,被称之为java代码片段,<% java代码片段 %>, 而<% session.getAttribute("sessionInfo") %> 称之为java表达式。
<%=request.getContextPath()%> 是为了解决相对路径的问题,可返回站点的根路径。
request.getContextPath() 应该是得到项目的名字,如果项目为根目录,则得到一个“”,即空的字条串。如果项目为abc,<%=request.getContextPath()%> 将得到abc,服务器端的路径会自动加上,<a href="XXX.jsp"> 是指当前路径下的这个xxx.jsp页面,有时候也可以在head里设置html:base来解决路径的问题,不过用的最多的还是reques.getContextPath。
session.getAttribute("sessionName") 的功能:用来得到对应名称的session值,即得到object对象。加(com.chint.until.SessionInfo)的作用是强制转换成com.chint.until.SessionInfo类型。
常用到的还有一个session.setAttribute("sessionName",Object)方法:该方法的功能是用来设置session值的,sessionName是名称,object是要保存的对象。
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
getContexPath(); 得到当前应用的根目录
getScheme(); 它返回当前请求所使用的协议,一般的应用返回“http”,对于ssl则返回“https”
getServerName(); 获取服务器名字,如果是在本地的话就是localhost
getServerPort(); 获得服务器的端口号
request.getContextPath()的功能相关推荐
- request.getcontextPath() 详解
<%=request.getContextPath()%>是为了解决相对路径的问题,可返回站点的根路径. 但不用也可以,比如<a href="<%=request.g ...
- String path = request.getContextPath()和String basePath = request.getScheme()
在JSP当中我们会用此代码来拼接路径,所以此语句是用来拼装当前网页的相对路径的. <% String path = request.getContextPath(); String basePa ...
- jsp中String path = request.getContextPath()的作用
<% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+ ...
- request.getContextPath()取不到值
request.getContextPath()得到项目的名字 如果项目为根目录,则得到一个"",即空的字条串, 如果项目为abc, <%=request.getContex ...
- String path = request.getContextPath(....拼装当前网页的相对路径
原文地址 <% String path = request.getContextPath(); String basePath = request.getScheme()+"://&q ...
- 关于request.getServletPath(),request.getContextPath()的总结
最近对于request中的几种"路径"有点混淆,查找网上资源都没有很好的总结,希望此文章能够帮助我理解一下这几种"路径". ++++++++++++++++++ ...
- String path = request.getContextPath
<%String path = request.getContextPath();String basePath = request.getScheme()+"://"+re ...
- request.getcontextPath() 详解(转)
本文转自:http://blog.csdn.net/pengxuan/article/details/6604578 <%=request.getContextPath()%>是为了解决相 ...
- request.getContextPath详解
<% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+ ...
最新文章
- AIFramework框架Jittor特性(下)
- 一个多年网络工程师总结的工作实用经验
- Spark之SQL解析(源码阅读十)
- svn命令行使用说明
- 前端学习(2439):jsonbin-init的使用
- 路由器下一跳地址怎么判断_网络基本功三:细说路由器
- 【5岁小孩对唱情歌 超萌超可爱】
- 一文讲清楚FusionInsight MRS CDL如何使用
- SpringBoot+Redis 搞定搜索栏热搜、不雅文字过滤功能
- easyui框架中关于dialog自带关闭事件的使用
- 《C程序设计语言》笔记 (三) 控制流
- 宝鸡市二检理科数学跟踪训练题
- Unable to find setter method for attribute: [commandName]
- rf扫描枪_RF枪是什么,怎么用,在哪用?
- 启发式搜索之八皇后问题
- MySQL 8.0.27 下载安装与配置详细教程(Windows64位)
- python数据可视化毕业设计题目_python:数据可视化
- 平凡程序员一年又一年的感悟(2019)
- 获取按键精灵论坛网页源文件
- vue3使用useMouseInElement实现图片局部放大预览效果