1、打開tomcat下的server.xml文件,路徑\apache-tomcat-7.0.62\conf文件夾下。
2、下<host></host>加入<Context path="/ompa/uploads/" docBase="G:\ompa\uploads\" reloadable="true"></Context> 配置path="imgPath"是Jsp中img標簽的src屬性用到訪問路徑,docBase="G:\ompa\uploads\"是本地路徑
代碼如下:
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="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" />
<Context path="/ompa/uploads/" docBase="G:\ompa\uploads\" reloadable="true"></Context>
</Host>
3、啟動tomcat部署項目,jsp處代碼如下:
<img src="/ompa/uploads/aa.png" /> <!--/ompa/uploads/ 與上面的<Context path="/ompa/uploads/" ..>一致