您好,登錄后才能下訂單哦!
這篇文章主要介紹Jquery如何實現文件提交,文中介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們一定要看完!
首先引入文件jquery.js,jquery.form.js,jqueryMultiFile.js
JSP頁面中增加:
$(document).ready(function(){
$('#myfile').MultiFile({
accept:'jpg|png|bmp|gif',
max:10,
STRING: {
remove:'移除',
selected:'已經選擇了: $file',
denied:'對不起,不支持: $ext!',
duplicate:'文件重復:\n$file!'
},
autoIntercept:['ajaxForm']
});
}
$("#editRoomForm").ajaxForm({
url : "<%=basePath%>/smart/zone/updateRoom",
dataType : "json",
success:function(data){
if(data == -1){
},
error:function() {
}
});
Form中增加
<inputtype="file" name="myfile" id="myfile" ></input>
修改類型:enctype="multipart/form-data"
Java中
@RequestMapping(value = "/updateRoom")
@ResponseBody
public int updateRoom(@ModelAttribute("editRoomForm") MeetingRoomDTO room, String[] editUserGroupSelected,
@RequestParam MultipartFile[] myfile, HttpServletRequest request, HttpSession session) {
try {
ZoneDTO zone = zoneService.getZoneById(room.getZoneID());
if (myfile != null && myfile.length > 0) {
// 圖片存儲路徑
String path = request.getRealPath("/") + "resources\\p_w_picpaths\\room\\p_w_picpathName\\";
// 數據庫存儲路徑
String dbpath = "resources/p_w_picpaths/room/p_w_picpathName/";
// 圖片名稱
String p_w_picpathName = "";
String pathName = "";
for (MultipartFile file : myfile) {
String fileName = file.getOriginalFilename();
Random r = new Random();
Long Name = System.currentTimeMillis();
Name = Name + r.nextInt(900000) + 100000;
try {
FileUtils.copyInputStreamToFile(file.getInputStream(), new File(path + zone.getId() + "_"
+ Name + fileName.substring(fileName.indexOf("."))));
} catch (IOException e) {
LOGGER.error("會議室實景圖片上傳失敗" + e);
e.printStackTrace();
}
p_w_picpathName += zone.getId() + "_" + fileName + ",";
pathName += dbpath + zone.getId() + "_" + Name + fileName.substring(fileName.indexOf(".")) + ",";
}
zone.setNavigationMap(pathName);
zone.setImageName(p_w_picpathName);
}
if ("".equals(room.getCapacityStr())) {
room.setCapacity(0);
} else {
room.setCapacity(Integer.valueOf(room.getCapacityStr()));
}
room.setAudit(room.getEditAudit());
room.setIsValid(0);
zone.setIsValid(0);
zoneService.updateMeetingRoom(zone, room, editUserGroupSelected);
return 1;
} catch (ZoneExistException e) {
LOGGER.error("會議室已存在", e);
return -2;
} catch (WSMException e) {
// TODO Auto-generated catch block
LOGGER.error("修改會議室信息失敗" + e);
return -3;
}
}
以上是“Jquery如何實現文件提交”這篇文章的所有內容,感謝各位的閱讀!希望分享的內容對大家有幫助,更多相關知識,歡迎關注億速云行業資訊頻道!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。