jsp中获取项目根路径:

  方法①

  最顶部增加代码:

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

  然后在head标签增加代码:

<base href="<%=basePath%>">

  结果为:http://localhost:8080/MyWeb/

  

  方法②

  只在head标签引入JSTL表达式

<base href="${pageContext.request.contextPath}">

  结果为:/MyWeb

idea下使用方法①有些情况下,例如maven下会报错,可以点此查看解决方法

JavaWeb项目根路径问题的更多相关文章

  1. JavaWeb 获取请求网络协议、IP、端口号、项目根路径

      JavaWeb 获取请求网络协议.IP.端口号.项目根路径 CreateTime--2018年6月1日16点32分 Author:Marydon 1.需求 在项目中,需要使用Java向本程序发送r ...

  2. java读取项目根路径下和任意磁盘位置下的properties文件

    1.读取项目根路径下的properties文件比较简单也是比较常见的一种操作. 具体代码如下: package com.xuanen.util; import java.util.Properties ...

  3. js获取网站项目根路径

    //js获取项目根路径,如: http://localhost:8083/uimcardprj function getRootPath(){ //获取当前网址,如: http://localhost ...

  4. js获取项目根路径

    //js获取项目根路径,如: http://localhost:8083/uimcardprj function getRootPath(){ //获取当前网址,如: http://localhost ...

  5. 在HTML页面中获取当前项目根路径的方法

    在HTML页面获取项目根路径的方法: function getRootPath(){ var curPageUrl = window.document.location.href; var rootP ...

  6. Springboot实体类转JSON报错Could not find acceptable representation & 设置访问项目根路径的默认欢迎页面

    =================实体类转JSON报错的解决办法============= 之前在springmvc的时候也报过这个错,原因以及springmvc中解决办法参考:https://www ...

  7. js获取当前项目根路径URL (转自CSDN 红领巾-sunlight)

    /** * //获取当前项目根路径 * @return {TypeName} */ function getRootPath(){ //获取当前网址,如: http://localhost:8083/ ...

  8. Java中获取项目根路径和类加载路径的7种方法

    引言 在web项目开发过程中,可能会经常遇到要获取项目根路径的情况,那接下来我就总结一下,java中获取项目根路径的7种方法,主要是通过thisClass和System,线程和request等方法. ...

  9. html 获取项目根路径

    html 获取项目根路径 function getContextPath(){ var pathName = document.location.pathname; //当前文件的绝度路径 var i ...

随机推荐

  1. 不同目录存在相同名称的py文件,执行时,报错的解决方法

    1.问题现象如下,执行时报错  imported module 'test_case_execution' has this __file__ attribute platform win32 -- ...

  2. 桥接模式(python)

    from abc import ABCMeta, abstractmethod class Shape(metaclass=ABCMeta): def __init__(self, color): s ...

  3. 查询Oracle数据库的字符集

    How do you check the Oracle database character set? SQL> select value from nls_database_parameter ...

  4. js 将数字型 的字符串 转 数字 【整数 /浮点型数字】

    1. js 提供了两种可以将 数字型 的字符串 转 数字 的方法 parseInt()和parseFloat(), parseInt() 是转成整数, 但 向下去整数 , parseFloat() 是 ...

  5. kafka学习笔记(三)kafka的使用技巧

    概述 上一篇随笔主要介绍了kafka的基本使用包括集群参数,生产者基本使用,consumer基本使用,现在来介绍一下kafka的使用技巧. 分区机制 我们在使用 Apache Kafka 生产和消费消 ...

  6. JAVA并发-AQS知识笔记

    概述 AQS是AbstractQueuedSynchronizer的缩写,翻译成中文就是抽象队列同步器,AbstractQueuedSynchronizer这个类也是在java.util.concur ...

  7. JDK8 一文搞定👍

    ! https://zhuanlan.zhihu.com/p/442182870 Java8 新特性 学习来源于 B站 尚硅谷yyds Java学习源码 2021/11/22 距离,过年还有 57 天 ...

  8. Android官方文档翻译 一 Getting Started

    Getting Started 让我们开始吧! Welcome to Training for Android developers. 欢迎来到Android开发者训练营. Here you'll f ...

  9. 设置图片DPI

    //image 可以先转换为 bitmap Bitmap bmp = new Bitmap(width, height); bmp.SetResolution(300, 300);

  10. 微服务架构 | *2.3 Spring Cloud 启动及加载配置文件源码分析(以 Nacos 为例)

    目录 前言 1. Spring Cloud 什么时候加载配置文件 2. 准备 Environment 配置环境 2.1 配置 Environment 环境 SpringApplication.prep ...