• 上传文件


    三、接收文件

    request.setCharacterEncoding("UTF-8");
    // 文件保存路径
    String path = request.getSession ().getServletContext ().getRealPath ("/")
                			+"tmp_jkhd_booking\aa.pdf";
                	//		+request.getParameter("filename");
                
    InputStream is = request.getInputStream();
    OutputStream os = new FileOutputStream(path);
    int bytesRead = 0;
    byte[] buffer = new byte[8192];
    while ((bytesRead = is.read(buffer, 0, 8192)) != -1) {
        os.write(buffer, 0, bytesRead);
    }
    

    四、接收流

    strust1

    InputStreamReader isr = null;
    BufferedReader bf = null;
    StringBuffer protocolXML = new StringBuffer("");
    try {
      String s = "";
      request.setCharacterEncoding("UTF-8");
      isr = new InputStreamReader(request.getInputStream(), "UTF-8");
      bf = new BufferedReader(isr);
      while((s = bf.readLine())!=null){
        protocolXML.append(s);
      }
      bf.close();
      isr.close();
    } catch (IOException e) {
      e.printStackTrace();
    } finally {
      bf.close();
      isr.close();
    }
    

    strust2

     

    public String doUploadMapFile (@RequestParam (value = "uploadfile", required = false) MultipartFile uploadfile,   HttpServletRequest request)  {  
      
           Map <String, Object> data = new HashMap <String, Object> ();  
           boolean result = Boolean.TRUE;  
           // 定义容器接收文件名  
           String uploadFileName = null;  
           try  
           {  
      
               InputStreamReader read = new InputStreamReader (uploadfile.getInputStream (), "utf-8");// 考虑到编码格式  
               BufferedReader bufferedReader = new BufferedReader (read);  
               StringBuffer jsonContent = new StringBuffer ();  
      
               String content = "";  
               while ((content = bufferedReader.readLine ()) != null)  
               {  
                   jsonContent.append (content);  
               }  
               String brProjectPath = request.getSession ().getServletContext ().getRealPath ("/");  
               uploadFileName = uploadfile.getOriginalFilename ();  
               // 文件保存路径  
               String filePath = brProjectPath + "map\" + uploadFileName;  
               File date = new File (filePath);  
               FileOutputStream fop = null;  
               fop = new FileOutputStream (date);  
      
               byte[] contentInBytes = jsonContent.toString ().getBytes ();  
               fop.write (contentInBytes);  
               fop.flush ();  
               fop.close ();  
               read.close ();  
    

       

    一、预览图片(blob)

    <div>
        <input class="easyui-filebox" 
          labelPosition="top"
           data-options="buttonText:'选择文件', accept:'application/pdf',onChange:function(){view_file(this)} "        style="90%"> <div> <div style="margin-top:20px">   <a href="#" class="easyui-linkbutton" style="30%" onclick="upload_file()">预约</a>   <img id="pdf_view"></img> </div> // 上传时,触发的事件
    function view_file(_obj) {   // 获取当前上传的file的路径   var _filepath = $(_obj).filebox("getValue");   var _file = document.getElementById('filebox_file_id_1').files[0];   $('#pdf_view').attr("src", getObjectURL(_file))
    } // 获取file的本地浏览器对应路径 function getObjectURL(_file) {   var url = null;   if (window.createObjectURL != undefined) {     url = window.createObjectURL(_file);   } else if (window.URL != undefined) {     url = window.URL.createObjectURL(_file);   } else if (window.webkitURL != undefined) {     url = window.webkitURL.createObjectURL(_file);   }   return url; }

    二、pdf 预览(jquery.metadata.js

    http://jquery.malsup.com/media/

    http://jquery.malsup.com/media/misc.html

    <script type="text/javascript" src="http://github.com/malsup/media/raw/master/jquery.media.js?v0.92"></script>
    <script type="text/javascript" src="jquery.metadata.js"></script>
    
    ...
    
    <a class="media" href="guice.pdf">PDF File</a>
    <a class="media {type: 'html'}" href="../">HTML File</a>
  • 相关阅读:
    FineBI与power BI,一个是国外风生水起的微软巨头,一个是方兴未艾的国产BI厂商领导者
    Linux下的crontab定时执行任务命令详解举例
    手把手教你搭建SSH框架(Eclipse版)
    一、连接池的定义
    centos安装sftp服务win搭建 sftp 服务器
    前往阿里云的企业优惠活动页面
    世界可能是思想最为混乱的时候,无论你说什么
    python面向对象编程class1
    Python 文件I/O 文件读写模式r,r+,w,w+,a,a+的区别
    Python中的装饰器是你进入Python大门的一道坎,不管你跨不跨过去它都在那里
  • 原文地址:https://www.cnblogs.com/MissRabbit/p/8349721.html
Copyright © 2020-2023  润新知