springMVC easyUI filebox 單個檔案上傳,springmvceasyui
被這個檔案上傳坑到現在,還是自己技術問題,照著之前extjs項目那邊的上傳執行個體,愣是上傳不了
到後面就查了下springMVC的檔案上傳,按照那樣搞定了http://blog.csdn.net/jadyer/article/details/7575934
easyui 前端檔案
<form id="brandAddForm" method="post" enctype="multipart/form-data"> <table cellpadding="5"> <tr> <td>名稱:</td> <td><input class="easyui-textbox" type="text" name="name" data-options="required:true" style="width:200px"></input></td> </tr> <tr> <td>描述:</td> <td><input class="easyui-textbox" name="description" data-options="multiline:true" style="height:100px;width:200px"></input></td> </tr> <tr> <td>URL:</td> <td><input class="easyui-textbox" name="url" style="width:200px"></td> </tr> <tr> <td>LOGO:</td> <td><input class="easyui-filebox" name="sourceFile" style="width:200px"></td> </tr> <tr> <td>關鍵詞:</td> <td><input class="easyui-textbox" type="text" name="keywords" data-options="" style="width:200px"></input></td> </tr> </table></form>
springMVC 設定檔
<!-- SpringMVC上傳檔案時,需要配置MultipartResolver處理器 --> <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> <property name="defaultEncoding" value="UTF-8"/> <!-- 指定所上傳檔案的總大小不能超過200KB。注意maxUploadSize屬性的限制不是針對單個檔案,而是所有檔案的容量之和 --> <property name="maxUploadSize" value="200000"/> </bean> <!-- SpringMVC在超出上傳檔案限制時,會拋出org.springframework.web.multipart.MaxUploadSizeExceededException --> <!-- 該異常是SpringMVC在檢查上傳的檔案資訊時拋出來的,而且此時還沒有進入到Controller方法中 --> <bean id="exceptionResolver" class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver"> <property name="exceptionMappings"> <props> <!-- 遇到MaxUploadSizeExceededException異常時,自動跳轉到/WEB-INF/jsp/error_fileupload.jsp頁面 --> <prop key="org.springframework.web.multipart.MaxUploadSizeExceededException">error_fileupload</prop> </props> </property> </bean>
model
public class BrandModel {private Integer id;private String name;private String description;private String url;private String icon;private MultipartFile sourceFile; //對應<span style="font-family: Arial, Helvetica, sans-serif;"><input class="easyui-filebox" name="sourceFile" style="width:200px"></span> //set/get}
service 複製到你自己的目錄
FileUtils.copyInputStreamToFile(brandModel.getSourceFile().getInputStream(), new File(targetPath));
springMVC 返回json資料 前台jquery easyui 接受json卻提示 下載updateaction
struts裡面出現這種情況是在配置裡面加上 如下配置: <param name="contentType">text/html</param>
spring應該也類似吧...
為何我使用easyui與springmvc+hibernate+spring一起使用,easyui不起作用,我引的easyui的js路徑對的,
easyui怎麼還是jar包 啊?怎麼還放到lib下啊?easyui是js,跟jquery一樣用,用的時候在jsp頁面先引入jquery(必須),再引入easyui相關的js和css檔案。
<link rel="stylesheet" type="text/css" href="../css/bootstrap/easyui.css">
<link rel="stylesheet" type="text/css" href="../css/icon.css">
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script type="text/javascript" src="../js/jquery.easyui.min.js"></script>