Get the App
SLTechnology News&Howtos  ›  Development  › 

How to implement File submission by Jquery

Shulou Source: shulou.com Published: 2022-06-03 03:54:19 10月26日 Update

This article mainly introduces Jquery how to achieve file submission, the article is very detailed, has a certain reference value, interested friends must read it!

First introduce the file jquery.js,jquery.form.js,jqueryMultiFile.js

Add to the JSP page:

$(document) .ready (function () {

('# myfile') .MultiFile ({

Accept:'jpg | png | bmp | gif'

Max:10

STRING: {

Remove:' remove'

Selected:' has chosen: $file'

Sorry, denied:' is not supported: $extents'

Duplicate duplicate:' file:\ nduplicate fileholders'

}

AutoIntercept: ['ajaxForm']

});

}

("# editRoomForm") .ajaxForm ({

Url: "/ smart/zone/updateRoom"

DataType: "json"

Success:function (data) {

If (data =-1) {

}

Error:function () {

}

});

Added in Form

Modification type: enctype= "multipart/form-data"

In 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) {

/ / Image storage path

String path = request.getRealPath ("/") + "resources\\ p_w_picpaths\\ room\\ p_w_picpathName\"

/ / Database storage path

String dbpath = "resources/p_w_picpaths/room/p_w_picpathName/"

/ / Picture name

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 ("failed to upload live pictures of the conference room" + 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 ("Conference Room already exists", e)

Return-2

} catch (WSMException e) {

/ / TODO Auto-generated catch block

LOGGER.error ("failed to modify conference room information" + e)

Return-3

}

}

The above is all the contents of the article "how to achieve document submission by Jquery". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Tags: Documents meetings conference rooms pictures content articles paths storage value information interests names real scenes guys partners data databases more knowledge types Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker Apple Redmi NVidia Microsoft