我有以下文件夹结构:
ProjectFolder/images/some images
在同一个文件夹中
ProjectFolder/WEB-INF/classes/com/xyz/here is java file of controller.
如何获取 Controller 中的图片路径?
请帮忙。 谢谢:)
最佳答案
如果它的网络上下文可能是这样的东西可能会有所帮助
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);
关于java - Spring MVC :How to get file path into Controller?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8923466/