Примеры в этой статье делятся загрузкой файла Java и код реализации предварительного просмотра для вашей ссылки. Конкретный контент заключается в следующем
1. Загрузите плагин загрузки
2. index.html
<! Doctype html> <html lang = "en"> <head> <@head/> <script src = "<@path/>/js/uploadify-v3.1/jquery.uploadify-3.1.js"> </script> <link href = "<@path // js/uploadify-v3.1/uploadify.cselef" creef = "<@path // js/uploadify-v3.1/upludify.cseletify.cseletify.cseletify. type = "text/css"/> <style type = "text/css"> #uploader {позиция: относительно; } #uploader_queue {position: Absolute; Ширина: 600px; Слева: 200px; Верх: 0; } </style> <script type = "text/javascript"> $ (function () {$ ("#file_upload"). Flash 'uploader': '<@path // uploadattach.do', // 'width': 120, 'filetypedesc': 'ֻ поддерживает несколько форматов файлов', 'filetypeexts': '.dat; .264; .h264; .mp4; .dav; .mp4; '.mpg; .rmvb; .flv; .rm; .mov; .wmv; .jpg; .bmp; .png; .bmp; .jpg; .png;' + '.gif; .xlsx; .xls; .txt; '800KB', 'buttonText' : 'select file', 'uploadLimit' : 5, 'successTimeout' : 5, 'requeueErrors' : false, 'removeTimeout' : 10, 'removeCompleted' : false, 'queueSizeLimit' : 10, 'queueID' : 'uploader_queue', 'progressData' : 'speed', 'onInit' : function() { }, 'onuploadSuccess': function (файл, данные, ответ) {$ ("#uploader_view"). Append ('<img src = "<@path /> /upload /' + encodeuri (data) + '" /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br />') }, 'onqueueCOMPTETE': function (queudata) {$ ('#uploader_msg'). html (queuedata.uploadssuccessful + 'Загружено успешно <br/>'); }}); }); < /script> < /head> <body> <@chearer /> <br /> <br /> <br /> <br /> <div id = "uploader"> <p> <input type = "file" name = "file_upload" id = "file_upload" /> < /p> <a href = "javascript: $ ('#file_upload'). uploadify ('upload', '*')"> upload </a> <a href = "javascript: $ ('#file_upload'). uploadify ('stop')"> Отмена загрузки </a> <div = "upload_queue id = "uploader_msg"> </div> <div id = "uploader_view"> </div> </div> <br/> <br/> <br/> <br/> <@cooler/> </body> </html> 3. файлы Java
пакет com.frame.core.ctrl; Импорт java.io.file; Импорт java.io.filenotFoundException; Импорт java.io.fileOutputStream; импортировать java.io.ioexception; Импорт java.io.printwriter; импортировать java.util.date; импортировать java.util.map; импортировать java.util.uuid; Импорт javax.servlet.servletexception; Импорт javax.servlet.http.httpservletrequest; Импорт javax.servlet.http.httpservletresponse; Импорт org.apache.log4j.logger; Import org.springframework.sterotype.controller; Импорт org.springframework.ui.modelmap; Импорт org.springframework.web.bind.annotation.requestmapping; Импорт org.springframework.web.multipart.multipartfile; Импорт org.springframework.web.multipart.multiparthttpservletrequest; Импорт org.springframework.web.servlet.modelandView; @Controller public class loginctrl {private static logger log = logger.getlogger (loginctrl.class); @Requestmapping (value = "/goindex") public modelandView goindex () {modelandview mav = new ModelAndView ("index"); mav.addobject ("имя", "Мечсман"); mav.addobject ("ProjectName", "FreeMarker Framework"); вернуть мав; } @Requestmapping (value = "/login") public void login (httpservletrequest -запрос, httpservletresponse response) throws servletexception, ioexception {request.getSession (). Setattribute («Имя пользователя», «Идентификационная аутентикация сразу»); request.getRequestDispatcher ("/index.jsp"). } @RequestMapping ("/uploadAttach") public void ProcessUploadDir (ModelMap ModelMap, MultiparThttpServletRequest, PrintWriter Writer) Throws Exception {maping <String, MultipLatefile> filmap = request.getFileMap (); String path = request.getSession (). GetServletContext (). GetRealPath ("/") ;; System.out.println ("path:"+path); Дата CurrentTime = New Date (); long prefix = currentTime.getTime (); StringBuffer AttachIds = new StringBuffer (); for (map.Entry <string, multiplaRtfile> f: fileMap.EntrySet ()) {multiplaartFile file = f.getValue (); if (! islegalfile (file)) {string msg = " - незаконная файл"; бросить новое runtimeexception (msg); } String riginalFilename = prefix + "_" + file.getoriginalFilename (); File filedir = new File (path + "/upload" + file.separator); if (! filedir.exists ()) {filedir.mkdirs (); } File files = new File (path + "/opload" + file.separator + riginalfilename); FileOutputStream fileOutputStream = null; try {fileOutputStream = new FileOutputStream (files); fileOutputStream.write (file.getBytes ()); fileOutputStream.flush (); AttactIds.append (OriginalFilename + ","); } catch (filenotFoundException e) {e.printstackTrace (); } catch (ioException e) {e.printstackTrace (); } catch (Exception e) {e.printstackTrace (); } наконец {if (fileOutputStream! = null) {try {fileOutputStream.close (); } catch (ioException e) {e.printstackTrace (); }}}} writer.write (attiveIds.toString (). substring (0, attiveIds.toString (). Length ()-1)); } private final String [] filetype = new String [] {". Dat", ". 264", ". H264", ". Mp4", ". DAV", ". MP4", ". Avi", ". TS", ". Avi", ". MPG", ".rmvb", ". flv", ". ".xlsx", ". xls", ". txt", ". Pdf", ". Doc", ". Docx", ".rar", ". Zip", ". 7z"}; Private Boolean islegalfile (MultipartFile File) {string riginalFilename = file.getoriginalfilename (); for (string ft: fileType) {if (OriginalFilename.endSwith (ft)) {return true; }} вернуть false; }}Изображение воспроизведения:
Выше всего содержание этой статьи. Я надеюсь, что это будет полезно для каждого обучения, и я надеюсь, что все будут поддерживать Wulin.com больше.