如何显示位于服务器根目录下的jsp中的图片

How to display a image in jsp, which is located in root directory of server

我是 spring MVC 的新手,我有一个将图像存储在应用程序根目录中的应用程序。

目录是这样的:C:\Users\Golla\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps\medicalus\images23310234176.png

我的项目名称是medicalus,images文件夹是用来保存图片的。 现在我想检索它并将其显示在 jsp 页面中。我曾尝试放弃图像的完整路径并尝试添加 < mvc:resources> servlet 调度程序的标记,但其中 none 有效。

如何显示服务器根目录下的图片? 任何建议将不胜感激。

试试这个:

  1. 在Spring的配置文件中:

    <mvc:resources mapping="/images/**" location="/images/" />
    
  2. 在你JSP:

    <img src="${pageContext.request.contextPath}/images/1423310234176.png" />