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。

  • 相关阅读:
    GUID概念
    某猿的饭局
    SVN切分支步骤
    OSX:设置用户默认浏览器
    值得推荐的android开发框架简单介绍
    用实力让情怀落地!阅兵前线指挥车同款电视TCL&#160;H8800受捧
    Excel查询序列所相应的值-vLoopup函数,求比例分子改变但分母不变
    CSS3制作W3cplus的关注面板
    Spring MVC框架实例
    @property 和@synthesize
  • 原文地址:https://www.cnblogs.com/rdchen/p/9705466.html
Copyright © 2011-2022 走看看