zoukankan      html  css  js  c++  java
  • <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %>

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

    这个语句是用来拼接当前网页的相对路径的。

    <base herf="...">从来表明当前页面的相对路径所使用的根路径,也就是项目名称

    比如,页面内部有一个连接,完整的路径应该是 http://localhost:8085/Info_System/user/user_info.jsp
    其中http://server/是服务器的基本路径,Info_System是当前应用程序的名字,那么,我的根路径应该是那么http://localhost:80/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
    版权声明:本文为博主原创文章,转载请附上博文链接!

  • 相关阅读:
    二叉树的镜像(剑指offer-18)
    树的子结构(剑指offer-17)
    合并两个有序链表(剑指offer-16)
    OutOfMemory相关问题(内存溢出异常OOM)
    Java内存区域
    招银网络(一面06.29)
    反转链表(剑指offer-15)
    链表中倒数第k个节点(剑指offer-14)
    调整数组顺序使奇数位于偶数前面(剑指offer-13)
    数值的整数次方(剑指offer-12)
  • 原文地址:https://www.cnblogs.com/shundong106/p/10217912.html
Copyright © 2011-2022 走看看