zoukankan      html  css  js  c++  java
  • 视频(其他)下载+tomcat 配置编码+图片上传限制大小

    视频下载:
    前台 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>
  • 相关阅读:
    用Jetpack的Site Accelerator为网站CDN加速
    习惯了安逸的日子永远不知道折腾了才叫人生
    谷歌2019年最热门搜索词榜单公布
    如何隐藏WooCommerce Shop Page页面的标题
    woocommerce调用分类描述另一种方法
    修改woocommerce列表产品显示数量
    centos用手机号无法登入安全狗的解决方法
    centos安装安全狗5步就能完成
    centos安装安全狗提示Need system command 'locate' to install safedog for linux的解决方法
    yoast breadcrumb面包屑导航修改去掉product
  • 原文地址:https://www.cnblogs.com/loveweiwei/p/4154651.html
Copyright © 2011-2022 走看看