tomcat中服务器路径和本地路径的映射,解决项目中图片显示的问题

项目中遇到的需要做图片的展示,但是在实际操作中发现自己的根路径和图片路径拼接后的图片路径是没有办法正确显示图片的

解决办法:
在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应用程序按需触发已部署应用程序的重新加载。

参考

猜你喜欢

转载自blog.csdn.net/hello_world_1996/article/details/112854732