Why does servletContext.getRealPath returns null on tomcat 8?

♀尐吖头ヾ 提交于 2019-12-01 01:00:35

问题


I have the following code line:

servletContext.getRealPath("resources/images/video_icon.png")

Wen I run application using jetty(using maven plugin) this code line return corect value.

When I run application using tomcat 8(on tomcat 7 it works) - application returns null.

application structure:

1.How to fix it?
2.Why does it happen?


回答1:


after adding / in the path beginning it works for both: jetty and tomcat 8

servletContext.getRealPath("/resources/images/video_icon.png")


来源:https://stackoverflow.com/questions/32197494/why-does-servletcontext-getrealpath-returns-null-on-tomcat-8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!