0
中不起作用我試圖使用a href =「block」顯示文件。文件上傳路徑在<a href="path" target="_blank">元素
我正在使用Spring MVC上傳文件。
以下是我對HTML上傳代碼: -
<form method="POST" action ="uploadDocument.htm" enctype="multipart/form-data">
Please select your resume to upload : (.pdf, .doc , .docx)<br/>
<input type="file" name="fileUpload" size="50" required/><br/><br/>
<input type="submit" value="Upload"/>
</form>
以下是控制器代碼: -
@RequestMapping(value="/uploadDocument.htm", method=RequestMethod.POST)
public String uploadFile(@RequestParam CommonsMultipartFile fileUpload,Model model,HttpServletRequest request) throws Exception{
HttpSession session = request.getSession();
UserAccount userAccount = (UserAccount)session.getAttribute("user");
String contentType = fileUpload.getContentType();
String format="";
if(contentType.contains("pdf") || contentType.contains("vnd") || contentType.contains("msword")){
if(contentType.contains("pdf")){
format=".pdf";
}
else if(contentType.contains("vnd")){
format=".docx";
}
else if(contentType.contains("msword")){
format = ".doc";
}
String fileName = userAccount.getUsername()+format;
System.out.println(fileName);
String path ="E:\\eclipse\\workspace\\Zingo_Project\\src\\main\\webapp\\fileupload\\";
fileUpload.transferTo(new File(path+fileName));
model.addAttribute(fileName);
return "fileUploadSuccessfull";
}
return "uploadUserFailure";
}
我可以看到在需要的位置上載的文件。 當我嘗試訪問fileUploadSuccessfull.jsp中的文件時。
以下是我的代碼fileUploadSuccessfull.jsp。
File upload Successfull!<br/>
</br>
<a href="E:\New version\eclipse\workspace\Zingo_Project\src\main\webapp\fileupload\zingo.pdf" target="_blank">Click here to View the File</a>
當我點擊鏈接時,我無法在新窗口中查看該文件。
我已經困在這裏了幾個小時,我試圖給
href as "file:///E:/New%20version/eclipse/workspace/Zingo_Project/src/main/webapp/fileupload/zingo.pdf"
or
"${pageContext.request.contextPath}/fileupload/zingo.pdf"
請幫助我,我一直在這裏堅持了幾個小時。
感謝, 驚鼓
HTTP狀態404 - /fileupload/zingo.pdf 這是我得到 錯誤和URL說http:// localhost:8080/fileupload/zingo.pdf – quickBongo 2013-04-25 04:23:37
1.確定你的應用沒有像localhost:8080/webapp/fileupload/zingo.pdf這樣的子文件夾? 2.確定pdf在這個文件夾中?你可以在你的操作系統中打開它嗎? – 2013-04-25 04:32:04
webapp /下存在子文件夾「fileupload」,並且該文件也存在,我可以在我的操作系統中在所需文件夾中打開它。 – quickBongo 2013-04-25 04:36:03