这篇文章主要介绍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进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。