修改 tomcat/conf/server.xml 文件
在 host 下面添加 如下代码
<!-- docBase 图片路径 path 代表访问路径 -->
<Context docBase="/opt/images/" path="/upload/images/"/>
其中 docBase 图片路径 path 代表访问路径
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<Context docBase="/opt/images/" path="/upload/images/"/>
<!-- 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>
如上 上传图片的放在 /opt/images/ 目录下,通过 http://xxxx/upload/images/xxx.jpg 访问图片;