日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

ckeditor java 上传_java使用CKEditor实现图片上传功能

發(fā)布時間:2024/9/27 编程问答 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ckeditor java 上传_java使用CKEditor实现图片上传功能 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

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

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

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

刪除image.js中包含在雙引號中的上述文本

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

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

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

@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 m = new hashmap();

if (!servletfileupload.ismultipartcontent(request)) {

m.put("error", 1);

m.put("message", "請選擇文件!");

//return m;

logger.info("請選擇文件!");

}

string originalfilename=null;//上傳的圖片文件名

string fileextensionname=null;//上傳圖片的文件擴展名

for (multipartfile file : upload) {

if (file.getsize()> 10*1024* 1024) {

out.println("

out.println("window.parent.ckeditor.tools.callfunction(" + callback

+ ",''," + "'文件大小不得大于10m');");

out.println("");

}

originalfilename=file.getoriginalfilename();

logger.info("上傳的圖片文件名="+originalfilename);

fileextensionname= originalfilename.substring(

originalfilename.lastindexof(".") ,originalfilename.length()).tolowercase();

logger.info("圖片文件擴展名="+fileextensionname);

string[] imageextensionnamearray= websiteconstant.image_extension_name_array;

string allimageextensionname="";

boolean iscontain=false;//默認不包含上傳圖片文件擴展名

for(int i=0;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;

// 返回"圖像信息"選項卡并顯示圖片 ,在對應(yīng)的文本框中顯示圖片資源url

out.println("

out.println("window.parent.ckeditor.tools.callfunction(" + callback

+ ",'" +imageurl + "','')");

out.println("");

}else{

out.println("

out.println("window.parent.ckeditor.tools.callfunction(" + callback

+ ",''," + "'文件格式不正確(必須為"+allimageextensionname+"文件)');");

out.println("");

}

}

}

}

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; // 操作成功

5.若是在maven項目中使用的ckeditor,需要在pom.xml中添加如下代碼:

com.ckeditor

ckeditor-java-core

3.5.3

6.最終效果圖

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持萬仟網(wǎng)。

希望與廣大網(wǎng)友互動??

點此進行留言吧!

總結(jié)

以上是生活随笔為你收集整理的ckeditor java 上传_java使用CKEditor实现图片上传功能的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。