这篇文章主要介绍Jquery如何实现文件提交,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!首先引入文件jquery.js,jquery.fORM.js,jqueryMultiFile
这篇文章主要介绍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如何实现文件提交”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注编程网JavaScript频道!
--结束END--
本文标题: Jquery如何实现文件提交
本文链接: https://lsjlt.com/news/83809.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-01-12
2023-05-20
2023-05-20
2023-05-20
2023-05-20
2023-05-20
2023-05-20
2023-05-20
2023-05-20
2023-05-20
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0