video Download:
Foreground JSP function Downvideo (value,row,index) {return' <a href= ' <%=basepath%>admin/video/video!filedown.ds?uname= ' +row.uname+ ' &filepath= ' +value+ ' "> download </a> ';} Backstage Java:action: Public voidFiledown () {fileutil.download (filepath, Getrequest (). GetParameter ("Uname") +filepath.substring (Filepath.lastindexof (".")), Filepath.length ()), GetResponse ()); }fileutil: Public Static voidDownload (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=" +NewString (Filename.getbytes ("GBK"), "Iso-8859-1")); Inch=NewFileInputStream (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]; inti = 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 Configuration code is Utf-8
69th Line in Tomcat Servlet.xml, plus uriencoding= "UTF-8" < port= "8080" protocol= "http/1.1" uriencoding= " UTF-8 " connectiontimeout=" 20000 " redirectport=" 8443 " />
Image upload Limit size
<formID= "Financialform"Action= "<%=basepath%>riskcontrol/website/review_borrow!financialuplaod.ds"Method= "POST"enctype= "Multipart/form-data"onsubmit= "return Checkusertype ()" > <inputtype= "hidden"name= "Usreid"value= "<%=_usreId%>" /> <inputtype= "hidden"name= "Borrowid"value= "<%=_borrowId%>" /> <inputtype= "File"name= "image"multiple= "multiple"ID= "Financialimages"/> <inputtype= "Submit"value= "Start upload"/> </form>
<script type= "Text/javascript" >functionCheckusertype () {varUsertype= "${login_session_key.usertype}"; if(! (usertype==2| | usertype==11) {alert ("Only financial wind control or HQ customer service can upload review material"); return false; }Else{ returnSubmitfile (); } } functionSubmitfile () {varFilearr = document.getElementById ("Financialimages"). files; if(filearr.length==0) {alert (' Please select the uploaded image! '); return false; } for(vari=0;i<filearr.length;i++){ varImagename=Filearr[i].name; varExtstart=imagename.lastindexof ("."); varext=imagename.substring (extstart,imagename.length). toUpperCase (); if(ext!= ". PNG "&&ext!=". JPEG "&&ext!=". JPG "&&ext!=". BMP ") {alert ("Image is limited to PNG,JPEG,JPG,BHMP format"); return false; } varFileSize = filearr[i].size/1024;if(parseint (filesize) >300) {alert (' picture cannot be greater than 300KB '); return false; } //$ (' #financialForm '). Submit (); } }</script>
Video (Other) download +tomcat configuration code + picture upload limit size