視頻下載:
前臺 jsp function downVideo(value,row,index){ return '<a href="<%=basePath%>admin/video/video!fileDown.ds?uname='+row.uname+'&filepath='+value+'">下載</a>' ; } 后臺java : action: public void fileDown() { FileUtil.download(filepath, getRequest().getParameter( "uname")+filepath.substring(filepath.lastIndexOf("." ),filepath.length()), getResponse()); } FileUtil: public static void download(String filepath, String filename, HttpServletResponse response) { response.setContentType( "application/x-download;charset=utf-8" ); OutputStream outp = null ; FileInputStream in = null ; try { response.addHeader( "Content-Disposition", "attachment;filename="+ new String(filename.getBytes("gbk"),"ISO-8859-1" )); in = new FileInputStream(ServletActionContext.getServletContext().getRealPath("/")+ filepath); outp = response.getOutputStream(); } catch (UnsupportedEncodingException e1) { e1.printStackTrace(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } byte [] b = new byte [1024 ]; int i = 0 ; try { while ((i = in.read(b, 0, 1024)) != -1 ) { outp.write(b, 0 , i); outp.flush(); } } catch (IOException e) { e.printStackTrace(); } finally { if (in != null ) { try { in.close(); } catch (IOException e) { e.printStackTrace(); } in = null ; } if (outp != null ) { outp = null ; } } }
tomcat 配置編碼為utf-8
在tomcat servlet.xml里面 第69行加上 URIEncoding="UTF-8" < Connector port ="8080" protocol ="HTTP/1.1" URIEncoding ="UTF-8" connectionTimeout ="20000" redirectPort ="8443" />
圖片上傳限制大小
< form id ="financialForm" action ="<%=basePath%>riskcontrol/website/review_borrow!financialUplaod.ds" method ="post" enctype ="multipart/form-data" onsubmit ="return checkusertype()" > < input type ="hidden" name ="usreId" value ="<%=_usreId%>" /> < input type ="hidden" name ="borrowId" value ="<%=_borrowId%>" /> < input type ="file" name ="image" multiple ="multiple" id ="financialImages" /> < input type ="submit" value ="開始上傳" /> </ form >
<script type="text/javascript"> function checkusertype(){ var usertype="${login_session_key.userType}" ; if (!(usertype==2||usertype==11 )){ alert( "只有財務風控或者 總部客服可以上傳復審材料" ); return false ; } else { return submitFile(); } } function submitFile(){ var fileArr = document.getElementById("financialImages" ).files; if (fileArr.length==0 ){ alert( '請選擇上傳的圖片!' ); return false ; } for ( var i=0;i<fileArr.length;i++ ){ var imageName= fileArr[i].name; var extStart=imageName.lastIndexOf("." ); var ext= imageName.substring(extStart,imageName.length).toUpperCase(); if (ext!=".PNG"&&ext!=".JPEG"&&ext!=".JPG"&&ext!=".BMP" ){ alert( "圖片限于PNG,JPEG,JPG,BHMP格式" ); return false ; } var filesize = fileArr[i].size/1024; if (parseInt(filesize)>300 ){ alert( '圖片不能大于300KB' ); return false ; } // $('#financialForm').submit(); } } </script>
?
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
