<del id="d4fwx"><form id="d4fwx"></form></del>
      <del id="d4fwx"><form id="d4fwx"></form></del><del id="d4fwx"><form id="d4fwx"></form></del>

            <code id="d4fwx"><abbr id="d4fwx"></abbr></code>
          • java使用CKEditor實(shí)現(xiàn)圖片上傳功能

            java如何使用CKEditor實(shí)現(xiàn)圖片上傳功能,具體內(nèi)容如下

            10年積累的成都做網(wǎng)站、網(wǎng)站制作經(jīng)驗(yàn),可以快速應(yīng)對(duì)客戶對(duì)網(wǎng)站的新想法和需求。提供各種問題對(duì)應(yīng)的解決方案。讓選擇我們的客戶得到更好、更有力的網(wǎng)絡(luò)服務(wù)。我雖然不認(rèn)識(shí)你,你也不認(rèn)識(shí)我。但先網(wǎng)站制作后付款的網(wǎng)站建設(shè)流程,更有佳縣免費(fèi)網(wǎng)站建設(shè)讓你可以放心的選擇與我們合作。

            1.根據(jù)實(shí)際需要下載指定的CKEditor

            java使用CKEditor實(shí)現(xiàn)圖片上傳功能

            2.刪除文件ckeditor/plugins/image/dialogs/image.js預(yù)覽框中文本內(nèi)容,并修改hidden屬性值為顯示上傳選項(xiàng)卡

            java使用CKEditor實(shí)現(xiàn)圖片上傳功能java使用CKEditor實(shí)現(xiàn)圖片上傳功能

            刪除image.js中包含在雙引號(hào)中的上述文本

            java使用CKEditor實(shí)現(xiàn)圖片上傳功能

            將image.js中的hidden屬性值改為0

            java使用CKEditor實(shí)現(xiàn)圖片上傳功能

            3.修改ckeditor/config.js文件,配置“上傳到服務(wù)器”按鈕調(diào)用的controller接口

            java使用CKEditor實(shí)現(xiàn)圖片上傳功能

            java使用CKEditor實(shí)現(xiàn)圖片上傳功能

            4.“上傳到服務(wù)器”按鈕調(diào)用的controller級(jí)別的接口

            @Controller 
            @RequestMapping("publicutil") 
            public class PublicUtilController { 
             
            @RequestMapping(value = "uploadImage") 
            private void uploadImage(HttpServletRequest request, HttpServletResponse response, HttpSession session,@RequestParam MultipartFile[] upload) { 
               
             response.setCharacterEncoding("UTF-8"); 
             PrintWriter out=null; 
             try { 
              out = response.getWriter(); 
             } catch (IOException e1) { 
              logger.error("response.getWriter()異常="+e1); 
              e1.printStackTrace(); 
             } 
             String callback = request.getParameter("CKEditorFuncNum"); 
               
             // 獲得response,request 
             Map<String, Object> m = new HashMap<String, Object>(); 
               
             if (!ServletFileUpload.isMultipartContent(request)) { 
              m.put("error", 1); 
              m.put("message", "請(qǐng)選擇文件!"); 
              //return m; 
              logger.info("請(qǐng)選擇文件!"); 
             } 
               
             String originalFileName=null;//上傳的圖片文件名 
             String fileExtensionName=null;//上傳圖片的文件擴(kuò)展名 
             for (MultipartFile file : upload) { 
              if (file.getSize()> 10*1024* 1024) { 
               out.println("<script type=\"text/javascript\">"); 
               out.println("window.parent.CKEDITOR.tools.callFunction(" + callback 
                  + ",''," + "'文件大小不得大于10M');"); 
               out.println("</script>"); 
                 
              } 
                
              originalFileName=file.getOriginalFilename(); 
              logger.info("上傳的圖片文件名="+originalFileName); 
              fileExtensionName= originalFileName.substring( 
              originalFileName.lastIndexOf(".") ,originalFileName.length()).toLowerCase(); 
              logger.info("圖片文件擴(kuò)展名="+fileExtensionName); 
                
              String[] imageExtensionNameArray= WebsiteConstant.IMAGE_EXTENSION_NAME_ARRAY; 
                
              String allImageExtensionName=""; 
              boolean isContain=false;//默認(rèn)不包含上傳圖片文件擴(kuò)展名 
              for(int i=0;i<imageExtensionNameArray.length;i++){ 
               if(fileExtensionName.equals(imageExtensionNameArray[i])){ 
                isContain=true; 
               }  
               if(i==0){ 
                allImageExtensionName+=imageExtensionNameArray[i]; 
               }else{ 
                allImageExtensionName+=" , "+imageExtensionNameArray[i]; 
               } 
                 
              } 
                
              String newFileName=java.util.UUID.randomUUID().toString()+fileExtensionName; 
              String uploadPath =WebsiteConstant.PIC_APP_FILE_SYSTEM_CKEDITOR_LOCATION; 
              if(isContain){//包含   
               File pathFile = new File(uploadPath); 
               if (!pathFile.exists()) { // 如果路徑不存在,創(chuàng)建 
                pathFile.mkdirs(); 
               } 
               try { 
                FileUtils.copyInputStreamToFile(file.getInputStream(), new File(uploadPath ,newFileName)); 
            //    InputStream is=file.getInputStream(); 
            //    File toFile = new File(uploadPath, newFileName); 
            //    OutputStream os = new FileOutputStream(toFile); 
            //    byte[] buffer = new byte[1024]; 
            //    int length = 0; 
            //    while ((length = is.read(buffer)) > 0) { 
            //     os.write(buffer, 0, length); 
            //    } 
            //    is.close(); 
            //    os.close(); 
               } catch (IOException e) { 
                logger.error("FileUtils.copyInputStreamToFile uploadPath="+uploadPath+" newFileName ="+newFileName+" exception="+e); 
               } 
               String imageUrl=WebsiteConstant.PIC_APP_SERVER_URL+"images/ckeditor/"+newFileName; 
               // 返回"圖像信息"選項(xiàng)卡并顯示圖片 ,在對(duì)應(yīng)的文本框中顯示圖片資源url 
               out.println("<script type=\"text/javascript\">"); 
               out.println("window.parent.CKEDITOR.tools.callFunction(" + callback 
                  + ",'" +imageUrl + "','')"); 
               out.println("</script>"); 
                 
              }else{ 
               out.println("<script type=\"text/javascript\">"); 
               out.println("window.parent.CKEDITOR.tools.callFunction(" + callback 
                  + ",''," + "'文件格式不正確(必須為"+allImageExtensionName+"文件)');"); 
               out.println("</script>"); 
              } 
             
             }  
             } 
             
            } 
            
            <span >public class WebsiteConstant { 
             
             public static String[] IMAGE_EXTENSION_NAME_ARRAY={".jpg",".jpeg",".png",".gif",".bmp"}; 
             public static String PIC_APP_SERVER_URL="http://localhost:8090/Picture/"; 
             public static String PIC_APP_FILE_SYSTEM_CKEDITOR_LOCATION="/Users/abc/Documents/tomcat/webapps/Picture/images/ckeditor/"; 
             public static final int SUCCESS = 1; // 操作成功 
            </span> 
            
            

            5.若是在Maven項(xiàng)目中使用的CKEditor,需要在pom.xml中添加如下代碼:

            <dependency> 
             <groupId>com.ckeditor</groupId> 
             <artifactId>ckeditor-java-core</artifactId> 
             <version>3.5.3</version> 
            </dependency> 
            
            

            6.最終效果圖

            java使用CKEditor實(shí)現(xiàn)圖片上傳功能

            以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持創(chuàng)新互聯(lián)。

            本文題目:java使用CKEditor實(shí)現(xiàn)圖片上傳功能
            當(dāng)前鏈接:http://www.jbt999.com/article14/jhdege.html

            成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供響應(yīng)式網(wǎng)站外貿(mào)網(wǎng)站建設(shè)、網(wǎng)站設(shè)計(jì)公司自適應(yīng)網(wǎng)站、定制網(wǎng)站搜索引擎優(yōu)化

            廣告

            聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:[email protected]。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

            成都網(wǎng)站建設(shè)公司

              <del id="d4fwx"><form id="d4fwx"></form></del>
              <del id="d4fwx"><form id="d4fwx"></form></del><del id="d4fwx"><form id="d4fwx"></form></del>

                    <code id="d4fwx"><abbr id="d4fwx"></abbr></code>
                  • 看一级黄色毛片 | 中国 免费XXXX18在线观看 | 午夜性视频 | 香蕉视频网站在线看视频二 | 亚洲视频中文 |