Video (Others) download + tomcat configuration encoding + Image Upload limit size,

Source: Internet
Author: User

Video (Others) download + tomcat configuration encoding + Image Upload limit size,

Video download:
Foreground jsp function downVideo (value, row, index) {return '<a href = "<% = basePath %> admin/video! FileDown. ds? Uname = '+ row. uname + '& filepath =' + value + '"> download </a>';} background 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 (FileNotFoundExcept Ion 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 is configured with UTF-8 encoding

In tomcat servlet. xml contains 69th lines with URIEncoding = "UTF-8" <Connector port = "8080" protocol = "HTTP/1.1" URIEncoding = "UTF-8" connectionTimeout = "20000" redirectPort = "8443 "/>

Maximum image upload size

<Form id = "terraalform" 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 = "alalimages"/> <input type = "submit" value = "Start upload"/> </form>
<Script type = "text/javascript"> function checkusertype () {var usertype = "$ {login_session_key.userType}"; if (! (Usertype = 2 | usertype = 11) {alert ("only financial risk control or headquarters customer service can upload review materials"); return false ;} else {return submitFile () ;}} function submitFile () {var fileArr = document. getElementById ("externalimages "). files; if (fileArr. length = 0) {alert ('select the uploaded image! '); 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 (" images are limited to PNG, JPEG, JPG, and BHMP Formats "); return false;} var filesize = fileArr [I]. size/1024; if (parseInt (filesize)> 300) {alert ('image cannot exceed 300KB '); return false ;}// $ (' # Your alform '). submit () ;}</script>

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.