项目中遇到的需要做图片的展示,但是在实际操作中发现自己的根路径和图片路径拼接后的图片路径是没有办法正确显示图片的
解决办法:
在tomcat的conf下的 server.xml中增加以下代码
代码放在<Host></Host>的里面即可

<Context path="/veptsPhotos" docBase="D:\photos" reloadable="true" />
-- path 映射路径 docBase 本地路径 reloadable 是否重载 (开发阶段是有用的,
但是上线的时候要设置为false )
Set to true if you want Catalina to monitor classes in
/WEB-INF/classes/ and /WEB-INF/lib for changes, and automatically
reload the web application if a change is detected. This feature is
very useful during application development, but it requires
significant runtime overhead and is not recommended for use on
deployed production applications. That’s why the default setting for
this attribute is false. You can use the Manager web application,
however, to trigger reloads of deployed applications on demand.
百度翻译:如果希望Catalina监视/WEB-INF/classes/和/WEB-INF/lib中的类的更改,并在检测到更改时自动重新加载WEB应用程序,请将其设置为true。此功能在应用程序开发期间非常有用,但它需要大量的运行时开销,不建议在已部署的生产应用程序上使用。这就是为什么此属性的默认设置为false。但是,您可以使用managerweb应用程序按需触发已部署应用程序的重新加载。

本文介绍了解决Tomcat服务器上图片路径配置问题的方法。通过在server.xml文件中添加Context元素来实现图片路径的正确映射,确保应用可以正常加载图片资源。
4477

被折叠的 条评论
为什么被折叠?



