Os exemplos deste artigo compartilham o código Java Upload e Visualize o código de implementação para sua referência. O conteúdo específico é o seguinte
1. Faça o download do plugin de uploadify
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.css" rel="stylesheet" type = "text/css"/> <style type = "text/css"> #upLoader {position: relativo; } #upLoader_queue {Posição: Absolute; Largura: 600px; Esquerda: 200px; topo: 0; } </style> <script type = "text/javascript"> $ (function () {$ ("#file_upload") .Uploadify ({'Auto': false, 'método': "Get", 'formData': {'pasta': 'arquivo', 'altura': '30,' suw ': '<@path // js/uploadify-v3.1/uploadify.swf', // Flash 'uploader': '<@path // uploadattach.do', // 'width': 120, 'filetypedesc': 'ֻ suporta vários formatos de arquivo', 'fileTypeexts': 'DAT; .264; H264; .mp4; .dav; .mp4; '.gif; .xlsx; .xls; .txt; .pdf; .doc; .docx; .Rar; .zip; .7z', 'fileSizelimit': '800KB', 'ButtonText': 'Select File', 'upload': 5, 'succcessTimeout': 5, 'Remenerer': ' : false, 'Queueuseizelimit': 10, 'QueueId': 'uploader_queue', 'ProgressData': 'Speed', 'oninit': function () {}, 'onupLoadSuccess': function (arquivo, dados, resposta) {$ ("#uploader_view). codeuri (dados) + '" /> <r /> <r /> <r /> <r /> <r /> <r /> <r /> <r /> <r />'); }, 'onqueuecplete': function (Queuedata) {$ ('#uploader_msg'). html (Queuedata.uploadsSuccessful + 'enviado com sucesso <br/>'); }}); }); < /script> </ad Head> <body> <@header /> <r /> <r /> <r /> <r /> <div id = "uploader"> <p> <input type = "file" name = "file_upload" id = "file_uppload" /> < / href = "javascript: $ ('#file_upload'). uploady ('upload', '*')"> upload </a> id = "uploader_msg"> </div> <div id = "uploader_view"> </div> </div> <r/> <r/> <r/> <r/> <@footer/> </body> </html> 3. Arquivos Java
pacote com.frame.core.ctrl; importar java.io.file; importar java.io.filenotfoundException; importar java.io.fileOutputStream; importar java.io.ioException; importar java.io.printwriter; importar java.util.date; importar java.util.map; importar java.util.uuid; importar javax.servlet.servletexception; importar javax.servlet.http.httpServletRequest; importar javax.servlet.http.httpServletResponse; importar org.apache.log4j.logger; importar org.springframework.tereotype.controller; importar org.springframework.ui.modelmap; importar org.springframework.web.bind.annotation.requestmapping; importar org.springframework.web.multipart.multipartFile; importar org.springframework.web.multipart.multiparthttpServletRequest; importar org.springframework.web.servlet.modelandView; @Controller public class Loginctrl {private estático logger log = logger.getLogger (loginctrl.class); @RequestMapping (value = "/goindex") public e ModelAndView goindex () {modelAndView MAV = new ModelAndView ("Index"); mav.addobject ("nome", "espadachim"); Mav.addObject ("ProjectName", "Freemarker Framework"); retornar mav; } @RequestMapping (value = "/login") public void Login (solicitação httpServletRequest, httpServletResponse resposta) lança servletexception, ioexception {request.getSession (). Setattribute ("nome de usuário", "autenticação de identidade obedecida"); request.getRequestDispatcher ("/index.jsp"). Forward (solicitação, resposta); } @RequestMapping ("/UPLOPTATH") public void ProcessUpleAddir (ModelMap ModelMap, MultiparthttpServletLey Solicy, PrintWriter Writer) lança a exceção {map <String, MultipartFile> filemap = request.getFilemap (); String path = request.getSession (). GetServletContext (). GetRealPath ("/") ;; System.out.println ("Path:"+Path); Data CurrentTime = new Date (); long prefix = currentTime.getTime (); StringBuffer AtcnetIds = new StringBuffer (); para (map.entry <string, multipartfile> f: filemap.entryset ()) {multipartfile file = f.getValue (); if (! islegalfile (arquivo)) {string msg = "é um arquivo ilegal"; lançar uma nova hora de execução (msg); } String originalfilename = prefixo + "_" + file.getoriginalfilename (); Arquivo arquivado = novo arquivo (caminho + "/upload" + file.separator); if (! filedir.exists ()) {filedir.mkdirs (); } Arquivos de arquivo = novo arquivo (caminho + "/upload" + file.separator + originalfilename); FileOutputStream fileOutputStream = null; tente {fileOutputStream = new FileOutputStream (arquivos); fileOutputStream.write (file.getBytes ()); fileOutputStream.flush (); ATCHIDS.APNEND (ORIGINALFILENAME + ","); } catch (filenotfoundException e) {e.printStackTrace (); } catch (ioexception e) {e.printStackTrace (); } catch (Exceção e) {e.printStackTrace (); } finalmente {if (fileOutputStream! = null) {try {fileOutputStream.close (); } catch (ioexception e) {e.printStackTrace (); }}}} writer.Write (ATCHIDS.TOSTRING (). Substring (0, ATCHIDS.ToString (). Length ()-1)); } String final privada [] FileType = novo String [] {". Dat", ". 264", ". ".rmvb", ". flv", ". rm", ". mov",. wmv ",. jpg", ". bmp", "png", ". bmp", ". ".xlsx", ". xls", ". txt", ". pdf", ". private boolean islegalfile (arquivo multipart -arquivo) {string originalfilename = file.getoriginalfilename (); for (string ft: filetype) {if (originalfilename.endswith (ft)) {return true; }} retornar false; }}Imagem de reprodução:
O exposto acima é todo o conteúdo deste artigo. Espero que seja útil para o aprendizado de todos e espero que todos apoiem mais o wulin.com.