关于

String path = request.getContextPath();

String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; 和

String basePath=http://localhost:8080/ 等同

开始学java的时候看不懂为什么这么写,今天复习的时候才搞懂:这个语句是用来拼接当前网页的相对路径的。

<base herf="...">从来表明当前页面的相对路径所使用的根路径,也就是项目名称
比如,页面内部有一个连接,完整的路径应该是 http://localhost:80/Info_System/user/user_info.jsp
其中http://server/是服务器的基本路径,Info_System是当前应用程序的名字,那么,我的根路径应该是那么http://localhost:8080/Info_System/。
 
用这个base,服务器就可以动态的将指定路径和页面的相对路径拼装起来,形成完整的路径。
  1.request.getSchema();可以返回当前页面所使用的协议,就是"http"
  2.request.getServerName();返回当前页面所在服务器的名字,就是上面例子中的"localhost"
  3.request.getServerPort();返回当前页面所在服务器的端口号,就是上面例子中的"8085"
  4.request.getContextPath();返回当前页面所在的应用的名字,就是上面例子中的"Info_System"
当前页面路径是:http://localhost:80/Info_System/uploadAttachs/attachs_list.jsp
根据上面的介绍,那么我在当前页面中有跳转为: <li><a href="<%=basePath%>user/user_info.jsp" class="information_off"></a></li>就应该这样写。

转载于: https://blog.csdn.net/haocm66/article/details/52998785

关于String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";的更多相关文章

  1. String path = request.getContextPath(); String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";作用!!!!!

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

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

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

  3. jsp中的<% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %>

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

  4. jsp页面String path = request.getContextPath(); String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";作用!!!!!

    转自:https://blog.csdn.net/kiwangruikyo/article/details/81130311 <%String path = request.getContext ...

  5. Struts2中 Path (getContextPath与basePath)

    struts2中的路径问题是根据action的路径而不是jsp路径来确定,所以尽量不要使用相对路径. 虽然可以用redirect方式解决,但redirect方式并非必要.解决办法非常简单,统一使用绝对 ...

  6. String path = request.getContextPath();这段什么用

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

  7. request.getcontextPath() 详解

    request.getcontextPath() 详解 文章分类:Java编程 <%=request.getContextPath()%>是为了解决相对路径的问题,可返回站点的根路径. 但 ...

  8. JSP之项目路径问题(${pageContext.request.contextPath},<%=request.getContextPath()%>以及绝对路径获取)

    本随笔这是作为一个记录使用,以备后查.项目完成之后本地部署OK,本地Linux部署OK,都可以正常的访问,可是当我把它部署到服务器上面的时候,首页可以正常访问,可是当发出请求的时候却报错误了,说找不到 ...

  9. request.getContextPath()

    今天终于明白了jsp中的request.getContextPath()是怎么回事了. request.getContextPath()  返回站点的根目录 request.getRealpath(& ...

随机推荐

  1. WebAPI之postman变量和session/token

    postman使用变量: 之前我们请求里面的主机地址都是localhost,表示本机.而在实际测试过程中,服务器地址往往并非是在本机上的,这时候就需要用到变量. postman支持多个测试环境,一个环 ...

  2. 基于CC1606 FPGA评估板移植iCamera程序小结

    iCamera作为柴草电子经典的摄像头开发工具,其强大的摄像头调试功能,深受广大网友喜爱,支持市面上各种摄像头. 目前现有的应用板卡支持:CC1601(CP601A). CC1602(CP601B) ...

  3. usb2.0高速视频采集之68013A寄存器配置说明

    任何的固件编程离不开与与原理图参考,图纸中所采用的是USB的Slave_fifo传输方式,具体配置与图纸对应即可. •USB_IFCLK:同步Slave_FIFO模式,输入频率范围5M-48M,在FP ...

  4. Python利用PyExecJS库执行JS函数

      在Web渗透流程的暴力登录场景和爬虫抓取场景中,经常会遇到一些登录表单用DES之类的加密方式来加密参数,也就是说,你不搞定这些前端加密,你的编写的脚本是不可能Login成功的.针对这个问题,现在有 ...

  5. vue-cli3配置webpack generate-asset-plugin

    最近尝试将vue项目中的后台URL抽离到打包后的配置文件中,看到有使用generate-asset-plugin在build时生成配置文件的做法,倒腾了一下午使该webpack plugin在vue- ...

  6. 面试题:为什么客户端最后还要等待2MSL

    面试题: 为什么客户端最后还要等待2MSL MSL(Maximum Segment Lifetime),TCP允许不同的实现可以设置不同的MSL值. 保证客户端发送的最后一个ACK报文能够到达服务器, ...

  7. Yii2 框架跑脚本时内存泄漏问题分析

    现象 在跑 edu_ocr_img 表的归档时,每跑几万个数据,都会报一次内存耗尽 PHP Fatal error:  Allowed memory size of 134217728 bytesex ...

  8. JS---DOM---为元素解绑事件

    解绑事件 注意:用什么方式绑定事件, 就应该用对应的方式解绑事件 1.解绑事件 对象.on事件名字=事件处理函数--->绑定事件 对象.on事件名字=null;   //1 对象.on事件名字= ...

  9. Linux7 64安装 oracle 11g Error in invoking target 'agent nmhs' of makefile

    在makefile中添加链接libnnz11库的参数修改$ORACLE_HOME/sysman/lib/ins_emagent.mk,将$(MK_EMAGENT_NMECTL)修改为:$(MK_EMA ...

  10. RF之关键字、变量、循环

    关键字的使用: RF的能力是由关键字提供的,所以,我们必须对RF的常用关键字有个了解 . 最常用的关键字就在RF的关键字中.http://robotframework.org 其中Builtin是标准 ...