jsp访问本地的磁盘图片与配置tomcat虚拟路径

将web程序部署到tomcat以后,就无法访问本地的图片。今天学到一个小技巧,比较省事。

在tomcat下的sever.xml文件中加入一句话,

 <!--
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"  
               prefix="localhost_access_log." suffix=".txt" pattern="common" resolveHosts="false"/>
        -->
      
     <Context crossContext="true" debug="0" docBase="F://Image" path="/image" reloadable="true">
     </Context>
      </Host>
    </Engine>
  </Service>
</Server>

意思是建立一个虚拟路径,当要访问F:/Image文件下的资源时,此时对应的路径为/image

在JSP中显示图片只需要这样写

 <body>
   <img align="top" src="/image/encoding.png" alt="encoding.png"/>
    <br>
  </body>
 

猜你喜欢

转载自blog.csdn.net/linwei_hello/article/details/90410577