本文介绍了Spring MVC:如何获取文件路径到Controller?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下文件夹结构:
ProjectFolder/images/some images
在同一个文件夹中
ProjectFolder/WEB-INF/classes/com/xyz/here is java file of controller.
如何获取控制器中的图像路径?
How can I get the image path in the controller?
请帮助。
谢谢:)
Please, help.Thanks :)
推荐答案
如果它的网络环境可能会有这样的帮助
If its a web context may be something like this could help
InputStream is = null ;
is = request.getSession().getServletContext().getResourceAsStream("/images/someimage.jpg");
或者可能是这样的:
InputStream is = null ;
String realPath = request.getSession().getServletContext().getRealPath("/images/someimage.jpg");
is = new FileInputStream(realPath);
这篇关于Spring MVC:如何获取文件路径到Controller?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!