zoukankan      html  css  js  c++  java
  • js或jsp 获取项目路径常用方法

    可以引入一个jsp,这个jsp的内容如下:

    <%@page pageEncoding="UTF-8" contentType="text/javascript; charset=UTF-8"%>
    //设置ContextPath
    var __ctx='<%=request.getContextPath()%>';

    <c:set var="ctx" value="${pageContext.request.contextPath}" />

    以后的jsp中,可以这样用

    <script type="text/javascript" src="${ctx}/js/dynamic.jsp"></script>

    或者

    window.location.href =__ctx+ "/zjdlbb/zjdlbball/zjdlbball/list.ht";

    知识扩展:

    getContextPath()是jsp获取路径的一种方式,返回当前页面所在的应用的名字

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

           request.getSchema(),返回的是当前 连接使用的协议,一般应用返回的是http、SSL返回的是https;

           request.getServerName(),返回当前页面所在的 服务器的名字

           request.getServerPort(),返回当前页面所在的服务器使用的端口,80;

           request.getContextPath(),返回当前页面所在的应用的名字

           getContextPath()

           以访问的jsp为:http://localhost:8080/oms/rep/index.jsp,工程名为/dmsb为例:

            request.getContextPath(),得到工程名:/oms;

            request.getServletPath(),返回当前页面所在目录下全名称:/rep/index.jsp;

            request.getRequestURL(),返回IE地址栏地址:http://localhost:8080/oms/rep/index.jsp;

            request.getRequestURI() ,返回包含工程名的当前页面全路径:/oms/rep/index.jsp。

  • 相关阅读:
    Algorithm --> 最长回文子串
    Algorithm --> 筛法求素数
    c++ --> const关键字总结
    c++ --> 友元函数
    c++ --> static关键字总结
    c++ --> 父类与子类间的继承关系
    c++ --> 操作符重载
    Java设计模式应用——观察者模式
    Ignite集群管理——基于静态IP的节点发现
    线性回归的应用——容量预测
  • 原文地址:https://www.cnblogs.com/rdchen/p/9705466.html
Copyright © 2011-2022 走看看