<%
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()的功能相关推荐

  1. request.getcontextPath() 详解

    <%=request.getContextPath()%>是为了解决相对路径的问题,可返回站点的根路径. 但不用也可以,比如<a href="<%=request.g ...

  2. String path = request.getContextPath()和String basePath = request.getScheme()

    在JSP当中我们会用此代码来拼接路径,所以此语句是用来拼装当前网页的相对路径的. <% String path = request.getContextPath(); String basePa ...

  3. jsp中String path = request.getContextPath()的作用

    <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+ ...

  4. request.getContextPath()取不到值

    request.getContextPath()得到项目的名字 如果项目为根目录,则得到一个"",即空的字条串, 如果项目为abc, <%=request.getContex ...

  5. String path = request.getContextPath(....拼装当前网页的相对路径

    原文地址 <% String path = request.getContextPath(); String basePath = request.getScheme()+"://&q ...

  6. 关于request.getServletPath(),request.getContextPath()的总结

    最近对于request中的几种"路径"有点混淆,查找网上资源都没有很好的总结,希望此文章能够帮助我理解一下这几种"路径". ++++++++++++++++++ ...

  7. String path = request.getContextPath

    <%String path = request.getContextPath();String basePath = request.getScheme()+"://"+re ...

  8. request.getcontextPath() 详解(转)

    本文转自:http://blog.csdn.net/pengxuan/article/details/6604578 <%=request.getContextPath()%>是为了解决相 ...

  9. request.getContextPath详解

    <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+ ...

最新文章

  1. AIFramework框架Jittor特性(下)
  2. 一个多年网络工程师总结的工作实用经验
  3. Spark之SQL解析(源码阅读十)
  4. svn命令行使用说明
  5. 前端学习(2439):jsonbin-init的使用
  6. 路由器下一跳地址怎么判断_网络基本功三:细说路由器
  7. 【5岁小孩对唱情歌 超萌超可爱】
  8. 一文讲清楚FusionInsight MRS CDL如何使用
  9. SpringBoot+Redis 搞定搜索栏热搜、不雅文字过滤功能
  10. easyui框架中关于dialog自带关闭事件的使用
  11. 《C程序设计语言》笔记 (三) 控制流
  12. 宝鸡市二检理科数学跟踪训练题
  13. Unable to find setter method for attribute: [commandName]
  14. rf扫描枪_RF枪是什么,怎么用,在哪用?
  15. 启发式搜索之八皇后问题
  16. MySQL 8.0.27 下载安装与配置详细教程(Windows64位)
  17. python数据可视化毕业设计题目_python:数据可视化
  18. 平凡程序员一年又一年的感悟(2019)
  19. 获取按键精灵论坛网页源文件
  20. vue3使用useMouseInElement实现图片局部放大预览效果

热门文章

  1. 蔡超:入门 Go 语言必须跨越的五个思维误区
  2. css元素居中方法归纳
  3. hdu1174(3维射线与圆是否相交)
  4. C# WinForm开发系列 - WebBrowser
  5. Delphi XE2 新控件 布局Panel TGridPanel TFlowPanel
  6. 美团2015校招哈尔滨站笔试题--第二题
  7. Linux基础常用运维操作
  8. “病毒防治”页面中“社区热帖”版块不显示
  9. 如果可能我们还是做好基础的事情吧
  10. new chosen courses at ifm