2010-12-13 36 views
3

我試圖使用spring和hibernate技術在我的freemarker頁面(ftl文件)中添加圖片上傳 - 這是我每次運行應用程序時發生的錯誤:使用freemarker上傳文件時的HTTP狀態500

HTTP狀態500 - 服務器 遇到內部錯誤(),該 阻止它履行這一 請求。

,這是代碼:

1-POM文件:

<dependency> 
    <groupId>commons-fileupload</groupId> 
    <artifactId>commons-fileupload</artifactId> 
    <version>1.2</version> 
</dependency> 
<dependency> 
    <groupId>org.apache.commons</groupId> 
    <artifactId>commons-io</artifactId> 
    <version>1.3.2</version> 
</dependency> 

2- APP-config.xml中:

<bean id="multipartResolver" 
class="org.springframework.web.multipart.commons.CommonsMultipartResolver"/> 

3- FTL文件:

<input type="file" id="image" name="image" value=""> 

4網絡控制器:

@RequestMapping(method= RequestMethod.POST) 
public String post(Model model , HttpServletRequest req , HttpSession session,@RequestParam("image") MultipartFile multipartFile) throws IOException{ 

    // transfer the uploaded image to the place where images exist in project 
    multipartFile.getBytes(); 
    File destination = new File("/home/user/Pictures/" + multipartFile.getOriginalFilename()); 
    multipartFile.transferTo(destination); 


    // delete the original uploaded image 
    destination.delete(); 


    return "redirect:index"; 

} 
+2

你可以發佈一些更多的錯誤日誌? – 2010-12-13 11:10:44

+1

是的,我們需要服務器上的錯誤日誌。如果這是一個自由標記問題,根據我的經驗,錯誤日誌非常有用。 – Andy 2010-12-13 16:05:52

+1

沒有例外或錯誤日誌出現,只是:「HTTP狀態500 - 服務器遇到一個內部錯誤(),阻止它履行此請求。」在瀏覽器中出現..我不知道問題到底在哪裏。 – se7so 2010-12-15 12:45:23

回答

1

一定要遵循Documentation信。通常情況下,您是否正確定義了<form>元素,其enctype屬性是否正確?

<form method="post" action="/form" enctype="multipart/form-data"> 

更多的提示,需要日誌,其他意見已經說過了。如果沒有寫入特定的日誌,那麼一定要將記錄器的閾值配置到較低的級別;儘管500代碼應該與ERROR級別的日誌相關,但很少被過濾掉。仔細檢查你的日誌配置! :)

HTH

+0

+1,我們的受訓者有同樣的問題,這是解決方案! 順便說一句,沒有在日誌中(WebLogic 10.3) – 2012-03-28 14:04:17

相關問題