一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

服務(wù)器之家:專注于服務(wù)器技術(shù)及軟件下載分享
分類導(dǎo)航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術(shù)|正則表達(dá)式|C/C++|IOS|C#|Swift|Android|VB|R語(yǔ)言|JavaScript|易語(yǔ)言|vb.net|

服務(wù)器之家 - 編程語(yǔ)言 - Java教程 - Java實(shí)現(xiàn)拖拽文件上傳dropzone.js的簡(jiǎn)單使用示例代碼

Java實(shí)現(xiàn)拖拽文件上傳dropzone.js的簡(jiǎn)單使用示例代碼

2020-12-02 14:25crush1988 Java教程

本篇文章主要介紹了Java實(shí)現(xiàn)拖拽文件上傳dropzone.js的簡(jiǎn)單使用示例代碼,具有一定的參考價(jià)值,有興趣的可以了解一下

Java實(shí)習(xí)生一枚,前端知識(shí)薄弱,最近因?yàn)楣ぷ餍枰隽艘粋€(gè)拖拽文件上傳的功能,發(fā)現(xiàn)dropzone.js挺不錯(cuò)的,特地做個(gè)筆記。

dropzonejs 的官網(wǎng)是:http://www.dropzonejs.com/, 中文手冊(cè)是:http://wxb.github.io/dropzonejs.com.zh-CN/

自己寫的拖拽文件至一個(gè)按鈕上傳的功能,前端及java代碼如下:

 jsp頁(yè)面:

1. 首先必須引入dropzone的js和css文件

?
1
2
<link rel="stylesheet" href="dropzone/css/dropzone.css" rel="external nofollow" >
<script src="dropzone/js/dropzone.js"></script>

 2.自己定義兩個(gè)div區(qū)域

?
1
2
3
4
5
6
7
<%--拖拽文件上傳 --%>
            <div id="div1" class="dropz" style="width:0px; height:0px;">
             uopload
            </div>
            <div id="div2" class="dropz" style=" background: white;border:none;float:left;">
              
            </div>

  這是我的文件上傳之后的文件隊(duì)列區(qū)域:

?
1
<div id="fileslist" style="padding: 10px;"></div>

3.對(duì)dropzone.css進(jìn)行修改,將文件內(nèi)的所有dropzone替換為dropz

 修改文件拖拽區(qū)域的顯示樣式:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
.dropz {/*設(shè)置拖拽上傳文件按鈕的格式*/
  min-height:0px;
  min-width: 100px;
  border: 1px solid #58AF0C;
  background: white;
  padding: 15px 20px;
  background-color: #7AC143;
  background-image: -webkit-gradient(linear, left bottom, left top, color-stop(0, #7AC143),
    color-stop(1, #7AC143));
  background-position: center top;
  background-repeat: no-repeat;
  border-radius: 5px;
  min-height:0px;
  min-width: 100px;
  padding: 15px 20px;   
  color: #FFF;
  font: bold 12px Arial, Helvetica, sans-serif;
  text-align: center;
  text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.25);
 }
 .dropz.dz-clickable {
  cursor: pointer;
  line-height: 0px;/*按鈕中的文字垂直居中*/
   }

4.在jsp對(duì)div進(jìn)行dropzone參數(shù)的自定義 

?
  • 1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    <script type="text/javascript">
      $("#div1").dropzone({
      url:"systemController.action?saveFile",//上傳文件的地址,
      maxFiles:1,//最多上傳幾個(gè)文件
      maxFilesize: 5,//文件的大小,單位是M
      addRemoveLinks:true,//是否有刪除文件的功能
      dictRemoveFile:"",//刪除文件
      previewsContainer:"#div2",//文件上傳進(jìn)度顯示的區(qū)域
      acceptedFiles: ".jpg,.jpeg,.png,.gif,.xls,.txt,.sql,.rar,.mkv",//支持的格式
      paramName:'file',//上傳的FILE名稱,即服務(wù)端可以通過(guò)此來(lái)獲取上傳的文件,如$_FILES['dropimage']
      init: function() {//初始化時(shí)的事件
        //$("#uploadfile").uploadFile({success:function(data){
         this.on("addedfile", function(file) {
     
          // Create the remove button
          var removeButton = Dropzone.createElement("<img src='plug-in/uploadify/img/uploadify-cancel.png' id="codetool">

     java后臺(tái)處理文件上傳的代碼: 

    ?
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    @RequestMapping(params = "saveFile", method = RequestMethod.POST)
      public void saveFile(HttpServletRequest request, HttpServletResponse response, TSDocument document) throws Exception{
        Map<String, Object> attributes = new HashMap<String, Object>();
        TSTypegroup tsTypegroup=systemService.getTypeGroup("fieltype","文檔分類");
        TSType tsType = systemService.getType("files","附件", tsTypegroup);
        String fileKey = oConvertUtils.getString(request.getParameter("fileKey"));// 文件ID
        String documentTitle = oConvertUtils.getString(request.getParameter("documentTitle"),"uploadfile");// 文件標(biāo)題
        if (StringUtil.isNotEmpty(fileKey)) {
          document.setId(fileKey);
          document = systemService.getEntity(TSDocument.class, fileKey);
          document.setDocumentTitle(documentTitle);
     
        }
        document.setBusinessKey(request.getParameter("businessKey"));
        document.setSubclassname(MyClassLoader.getPackPath(document));
        document.setCreatedate(DateUtils.gettimestamp());
        document.setTSType(tsType);
        UploadFile uploadFile = new UploadFile(request, document);
        uploadFile.setCusPath("files");
        uploadFile.setSwfpath("swfpath");
        document = systemService.uploadFile(uploadFile);
        attributes.put("url", document.getRealpath());
        attributes.put("fileKey", document.getId());
        if (ResourceUtil.getSessionUserName()!=null) {
          attributes.put("uploadUser", ResourceUtil.getSessionUserName().getUserName());
        }else{
          attributes.put("uploadUser", "null");
        }
        attributes.put("time", new SimpleDateFormat("yyyy-MM-dd").format(new Date()));
        attributes.put("name", document.getAttachmenttitle()+"."+document.getExtend());
        attributes.put("downloadurl", "commonController.action?viewFile&fileid="+ document.getId()+"&subclassname=");
        attributes.put("viewhref", "commonController.action?objfileList&fileKey=" + document.getId());
        attributes.put("delurl", "commonController.action?delObjFile&fileKey=" + document.getId());
        attributes.put("realPath", document.getRealpath());
        if(FileUtils.isPicture(document.getExtend())){
          attributes.put("imgUrl", document.getRealpath());
        }
        JSONObject js = new JSONObject(attributes);
        response.getWriter().write(js.toString());
        response.getWriter().flush();
      }

    注意這里的返回值是直接返回的json對(duì)象,如果采用

    ?
    1
    2
    @RequestMapping(params = "saveFiles", method = RequestMethod.POST)
      @ResponseBody

    則會(huì)報(bào)錯(cuò):

     

    復(fù)制代碼 代碼如下:

    [com.framework.core.common.exception.MyExceptionHandler]org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation 

     

     

    最終實(shí)現(xiàn)的效果如下:

    Java實(shí)現(xiàn)拖拽文件上傳dropzone.js的簡(jiǎn)單使用示例代碼

    更多使用功能請(qǐng)參考dropzone的官方文檔。

    以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持服務(wù)器之家。

    原文鏈接:http://blog.csdn.net/crush1988/article/details/75131079

    延伸 · 閱讀

    精彩推薦
    主站蜘蛛池模板: 美国高清xxxxx18| 亚洲一区二区三区久久精品 | 日韩大片免费观看 | 精品国产区一区二区三区在线观看 | 肥奶丰熟肥妇 | 男人操女人免费视频 | 欧美xingai| 2048论坛永久入口 原创合集 | 四虎影院在线免费播放 | 热99re国产久热在线 | 欧美精品v日韩精品v国产精品 | 日本特黄一级大片 | 美女毛片老太婆bbb80岁 | 狠狠干快播| 黄a在线观看| 99精品久久精品一区二区小说 | 亚瑟天堂久久一区二区影院 | 精品一区二区免费视频蜜桃网 | 日本一区二区三区在线 视频 | 国产精品aⅴ | 男女男精品视频 | 全黄一级裸片视频免费 | 风间由美被义子中文字幕 | 色里番52kkm全彩 | 久久国产精品福利影集 | 国产成人精品一区二区仙踪林 | 91天堂在线视频 | 日韩日日操 | 日日操天天射 | 97国产蝌蚪视频在线观看 | 我和老丈洗澡同性 | 2020韩国r级理论片在线观看 | 亚洲色大成网站www久久九九 | 精品国产一区二区在线观看 | 小小水蜜桃视频高清在线观看免费 | ak福利影院| 万域之王动漫在线观看全集免费播放 | 亚洲天堂在线视频播放 | 香蕉在线精品一区二区 | 亚洲香蕉伊在人在线观看9 亚洲系列国产系列 | 调教老师肉色丝袜的故事 |