Jquery如何实现文件提交
这篇文章主要介绍Jquery如何实现文件提交,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!
10年积累的成都做网站、成都网站制作经验,可以快速应对客户对网站的新想法和需求。提供各种问题对应的解决方案。让选择我们的客户得到更好、更有力的网络服务。我虽然不认识你,你也不认识我。但先做网站后付款的网站建设流程,更有桦南免费网站建设让你可以放心的选择与我们合作。
首先引入文件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中增加
修改类型: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如何实现文件提交”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注创新互联行业资讯频道!
网页名称:Jquery如何实现文件提交
标题网址:http://scyanting.com/article/pdcspg.html