有时候,jsp或者html等展示页面需要获取本地静态资源展示,比如img等;
但是现在浏览器禁止访问本地资源,解决方法如下:
我用的是tomcat,在server.xml 的<Host>节点内配置path和docBase,页面中使用 path即可,如下:
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<Context path="/file" docBase="d:\Images" debug="0" reloadable="true"/>
<!-- SingleSignOn valve, share authentication between web applications
Documentation at: /docs/config/valve.html -->
<!--
<Valve className="org.apache.catalina.authenticator.SingleSignOn" />
-->
<!-- Access log processes all example.
Documentation at: /docs/config/valve.html
Note: The pattern used is equivalent to using pattern="common" -->
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log." suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
</Host>
jsp页面使用方式:
<img id="testImg" alt="" src="/file/001.jpg">
如上:使用path的“/file” 就相当于docBase中配置的绝对路径