【发布时间】:2014-05-14 04:31:09
【问题描述】:
我一直在关注http://balusc.blogspot.in/2007/07/fileservlet.html,但我的代码无法正确使用,因为我不太了解它......
filePath = request.getServletContext().getRealPath("")+File.separator+"images"+File.separator+"photo.jpg";
System.out.println(filePath);
// Get requested file by path info.
String requestedFile = request.getPathInfo();
System.out.println(requestedFile);
// Check if file is actually supplied to the request URI.
if (requestedFile == null) {
// Do your thing if the file is not supplied to the request URI.
// Throw an exception, or send 404, or show default/warning page, or just ignore it.
response.sendError(HttpServletResponse.SC_NOT_FOUND); // 404.
System.out.println("terminates");
return;
}
我从中得到的是程序在此处终止,因为 requestedFile 一直为空...谁能帮我检查代码....任何帮助将不胜感激!!!提前谢谢!!!
【问题讨论】:
-
我真的一点都不懂...有没有你能帮我理解这个!!!
-
所以你想在 servlet 中读取文件?
-
是的!如果你能帮助我,我会很高兴!
-
image.jpg 的路径是什么??我的意思是真正的路径?
-
首先我将图像上传到位于此处“C:\Users\Roshan Shahukhal\Documents\NetBeansProjects\E-Drivers Licensing System\build\web\images\”的图像文件夹中。 . 现在我想检索该图像并显示在视图页面中!