當前位置:首頁 » 文件管理 » ckeditorjava上傳圖片

ckeditorjava上傳圖片

發布時間: 2022-12-10 21:32:04

Ⅰ 你好,看到你曾經的問題,java如何將文本中的圖片復制到ckeditor 3.0控制項後保存並上傳到伺服器上

ckeditor沒有提供這個功能,需要自己添加的!

Ⅱ ckeditor for java 如何上傳圖片

需要做的有以下幾步:
1. 到官網下載ckeditor
2. 復制到java web項目目錄下
3. 配置config文件,打開圖片上傳功能

CKEDITOR.editorConfig = function (config) {
// 換行方式
config.enterMode = CKEDITOR.ENTER_BR;
// 當輸入:shift+Enter是插入的標簽
config.shiftEnterMode = CKEDITOR.ENTER_BR;//
//圖片處理
config.pasteFromWordRemoveStyles = true;
config.filebrowserImageUploadUrl = "ckUploadImage.action?type=image";

// 去掉ckeditor「保存」按鈕
config.removePlugins = 'save';
};

4. java後台處理代碼
// 上傳圖片
@Action(value = "/ckUploadImage", results = { @Result(name = "success", location = "/upload.jsp") })
public String uploadImages() throws Exception {
HttpServletRequest request = ServletActionContext.getRequest();
FileOutputStream fos;
String webRoot = request.getSession().getServletContext().getRealPath(
"");
// 獲取圖片後綴名
String partRightType = uploadFileName.substring(uploadFileName
.lastIndexOf("."));
String CKEditorFuncNum = request.getParameter("CKEditorFuncNum");
// 判斷圖片的格式
if (!ImageFile.checkImageType(partRightType)) {
String path = "";
String alt_msg = "Sorry! Image format selection is incorrect, please choose GIF, jpeg, PNG format JPG, picture!";
pringWriterToPage("<script type='text/javascript'>window.parent.CKEDITOR.tools.callFunction("
+ CKEditorFuncNum
+ ", '"
+ path
+ "' , '"
+ alt_msg
+ "');</script>");
} else {
try {
uploadFileName = DateUtils.getDateNoStyle() + "-"
+ UUID.randomUUID() + partRightType;
String savePath = webRoot + Constants.UPLOAD_IMAGES_PATH;
File uploadFilePath = new File(savePath);
if (uploadFilePath.exists() == false) {
uploadFilePath.mkdirs();
System.out.println("路徑不存在,但是已經成功創建了" + savePath);
} else {
System.out.println("路徑存在了" + savePath);
}
fos = new FileOutputStream(new File(savePath + uploadFileName));
FileInputStream fis = new FileInputStream(getUpload());
byte[] buffer = new byte[1024];
int len = 0;
while ((len = fis.read(buffer)) > 0) {
fos.write(buffer, 0, len);
}
fos.close();
fis.close();
} catch (FileNotFoundException foe) {
System.out.println("上傳文件為0位元組");
}
// String path = "http://" + request.getServerName() + ":"
// + request.getServerPort() + request.getContextPath()
// + Constants.UPLOAD_IMAGES_PATH + uploadFileName;
String path = request.getContextPath()
+ Constants.UPLOAD_IMAGES_PATH + uploadFileName;
String alt_msg = "";
pringWriterToPage("<script type='text/javascript'>window.parent.CKEDITOR.tools.callFunction("
+ CKEditorFuncNum
+ ", '"
+ path
+ "' , '"
+ alt_msg
+ "');</script>");
}
return null;
}

* 其實重點的代碼就是這點
pringWriterToPage("<script type='text/javascript'>window.parent.CKEDITOR.tools.callFunction("
+ CKEditorFuncNum
+ ", '"
+ path
+ "' , '"
+ alt_msg
+ "');</script>");

Ⅲ ckfinder for java 如何使用ckeditor和ckfinder如何配置,(java、jsp)

到官方把ckfinder for java與ckeditor下載下來,ckfinder裡面會有一個WAR包,你直接把這個包部署到TOMCAT(或者你自己的應用伺服器)上,再將ckeditor文件夾與ckfinder文件夾放在同一級目錄里,打開ckfinder文件夾里的_samples下面的ckeditor.html,將<script type="text/javascript" src="/ckeditor/ckeditor.js"></script>修改為<script type="text/javascript" src="../ckeditor/ckeditor.js"></script>
再在瀏覽器里瀏覽ckeditor.html,看能不能上傳文件,呵呵。

Ⅳ ckeditor 4.1 調試成功後,發現沒有上傳圖片功能,如果配置出來呢

CKeditor可以配合CKfinder實現文件的上傳及管理。但是往往我們上傳的圖片需要某些自定義的操作,比如將圖片路徑寫入資料庫,圖片加水印等等操作。
實現原理:配置CKeditor的自定義圖標,單擊彈出一個子窗口,在在子窗口中上傳圖片實現我們的自己的功能,然後自動關閉子窗口將圖片插入到CKeditor的當前游標位置。
實現步驟:
1、配置CKeditor。網上很多資料,大家自己查。
2、配置config.js文件。此文件為CKeditor的配置文件。配置需要顯示的圖標。
1 CKEDITOR.editorConfig = function( config )
2 {
3// Define changes to default configuration here. For example:
4 config.language = 'zh-cn';
5 config.skin = 'v2';
6// config.uiColor = '#AADC6E';
7 config.toolbar =
8 [
9 ['Source', '-', 'Preview', '-'],
10 ['Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord'],
11 ['Undo', 'Redo', '-', 'Find', 'Replace', '-', 'SelectAll', 'RemoveFormat'],
12 '/',
13 ['Bold', 'Italic', 'Underline'],
14 ['NumberedList', 'BulletedList', '-', 'Outdent', 'Indent'],
15 ['JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock'],
16 ['Link', 'Unlink', 'Anchor'],
17 ['addpic','Flash', 'Table', 'HorizontalRule', 'Smiley', 'SpecialChar', 'PageBreak'],//此處的addpic為我們自定義的圖標,非CKeditor提供。
18 '/',
19 ['Styles', 'Format', 'Font', 'FontSize'],
20 ['TextColor', 'BGColor'],
21
22 ];
23
24 config.extraPlugins = 'addpic';
25
26 };
3、在CKeditor\plugins文件夾下新建addpic文件夾,文件夾下添加addpic.JPG圖標文件,建議尺寸14*13。addpic.JPG圖標文件即為顯示在CKeditor上的addpic的圖標。在圖標文件同目錄下添加文件plugin.js,內容如下。
1 (function () {
2//Section 1 : 按下自定義按鈕時執行的代碼
3var a = {
4 exec: function (editor) {
5 show();
6 }
7 },
8 b = 'addpic';
9 CKEDITOR.plugins.add(b, {
10 init: function (editor) {
11 editor.addCommand(b, a);
12 editor.ui.addButton('addpic', {
13 label: '添加圖片',
14 icon: this.path + 'addpic.JPG',
15 command: b
16 });
17 }
18 });
19 })();
文件中的show函數為顯示子頁面使用,我將它寫在CKeditor所在的頁面中。
4、edit.aspx頁面使用的js
edit.aspx頁面就是使用CKeditor的頁面。
function show() {
$("#ele6")[0].click();
}
function upimg(str) {
if (str == "undefined" || str == "") {
return;
}
str = "<img src='/html/images/" + str+"'</img>";
CKEDITOR.instances.TB_Content.insertHtml(str);
close();
}
function close() {
$("#close6")[0].click();
}
$(document).ready(function () {
new PopupLayer({ trigger: "#ele6", popupBlk: "#blk6", closeBtn: "#close6", useOverlay: true, offsets: { x: 50, y: 0} });
});
以上就是js的代碼,彈出窗口是使用jquery的彈出層,彈出層中嵌套iframe,iframe中使用upimg.aspx上傳頁面,大家如果有其他需要可以自己去設計彈出效果。為了大家調試方便,我將我實現彈出層的代碼貼出來。
彈出層效果使用的是popup_layer.js方案,需要進一步加工的朋友可以自己在網路中谷歌。ele6為彈出激發需要的層,blk6為彈出層主體,close6為層中承載關閉按鈕的層。代碼如下
<div id="ele6" style="cursor:hand; color: blue; display:none;"></div>
<div id="blk6" class="blk" style="display:none;">
<div class="head"><div class="head-right"></div></div>
<div class="main">
<a href="javascript:void(0)" id="close6" class="closeBtn"></a>
<iframe src="upimg.aspx"></iframe>
</div>
</div>
別忘記引用jquery和popup_layer.js。
5、upimg.aspx頁面
aspx代碼
<div>
<asp:FileUpload ID="FU_indexIMG" runat="server"/>
<br />
<asp:Button ID="Button1" runat="server" Text="上傳" onclick="Button1_Click"/>
<asp:Button ID="Button2" runat="server" onclick="Button2_Click" Text="取消"/>
</div>
對應的cs代碼
1protectedvoid Button1_Click(object sender, EventArgs e)
2 {
3string imgdir = UpImg();
4 script = "window.parent.upimg('" + imgdir + "');";
5 ResponseScript(script);
6 }
7protectedvoid Button2_Click(object sender, EventArgs e)
8 {
9string script = "window.parent.close();";
10 ResponseScript(script);
11 }
12///<summary>
13/// 輸出腳本
14///</summary>
15publicvoid ResponseScript(string script)
16 {
17 System.Text.StringBuilder sb = new System.Text.StringBuilder("<script language='javascript' type='text/javascript'>");
18 sb.Append(script);
19 sb.Append("</script>");
20 ClientScript.RegisterStartupScript(this.GetType(), RandomString(1), sb.ToString());
21 }
22///<summary>
23/// 獲得隨機數
24///</summary>
25///<param name="count">長度</param>
26///<returns></returns>
27publicstaticstring RandomString(int count)
28 {
29 RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
30byte[] data = newbyte[count];
31 rng.GetBytes(data);
32return BitConverter.ToString(data).Replace("-", "");
33 }
Button1_Click為確定按鈕的單擊事件函數。其中使用UpImg函數實現上傳圖片文件,我還在其中實現了加水印,縮圖,將圖片文件的大小以及相對路徑存入資料庫等自定義操作,大家可以在此發揮。UpImg返回值為保存圖片的相對路徑,然後調用editer.aspx頁面的js函數upimg。js函數upimg功能為將字元串插入到CKeditor的當前游標位置,插入的是html代碼。至此為止帶有新上傳圖片相對路徑的img標簽就插入CKeditor的編輯區了,能夠顯示圖片了。
Button1_Click為取消按鈕的單擊事件函數。調用editer.aspx頁面的js函數close,將彈出層隱藏。

Ⅳ CKEditor+CKFinder,上傳圖片成功,圖片鏈接正確,但是無法顯示,請問怎麼回事

1,將ckeditor解壓打開,打開_Samples,將ckeditor文件夾拷貝項目中的根目錄下,把bin放在根目錄下

2,將ckfinder解壓,ckfinder文件夾拷貝項目中的根目錄下,把bin放在根目錄下,把_sample,_source,help文件夾刪除掉,(註:沒有用)

3,在ckeditor文件下找到config.js 打開,找到
在CKEDITOR.editorCongig=function(config)
{
//填寫以下內容,圖片,flash路徑
config.uiColor = '#F7F8F9'
config.scayt_autoStartup = false
config.language = 'zh-cn'; //中文
config.filebrowserBrowseUrl = 'ckfinder/ckfinder.html';
config.filebrowserImageBrowseUrl = 'ckfinder/ckfinder.html?Type=Images';
config.filebrowserFlashBrowseUrl = 'ckfinder/ckfinder.html?Type=Flash';
config.filebrowserUploadUrl = 'ckfinder/core/connector/aspx/connector.aspx?command=QuickUpload&type=Files';
config.filebrowserImageUploadUrl = 'ckfinder/core/connector/aspx/connector.aspx?command=QuickUpload&type=Images';
config.filebrowserFlashUploadUrl = 'ckfinder/core/connector/aspx/connector.aspx?command=QuickUpload&type=Flash';
};

4,在ckfinder文件下找到config.ascx文件,打開
1)把public overrider bool ChekcAuthentication(){return false;改為:return true;}
2)public overrider void SetConfig(){BaseUrl = "~/ckfinder/userfiles/";}

5,在頁面中head標簽內寫入:
<script type="text/javascript" src="ckeditor/ckeditor.js" ></script>
<script type="text/javascript" src="ckfinder/ckfinder.js"></script>
如果有母版頁,在母版頁中寫
--註:單純的配置,6,7可以不要,但是一旦要入資料庫中,就要配置6.7步驟

6,在Default.aspx頁面中,寫入<%@Page ValidateRequest="false"%>

7,在web.config文件中,在system.web下寫 <httpRuntime requestValidationMode="2.0"/>

8,在Default.aspx頁面中添加<asp:TextBox ID="txtcontent" runat="server" TextMode="MultiLine" Height="503px" Width="100%" class="ckeditor" ></asp:TextBox>
<script type="text/javascript">
CKEDITOR.replace('<%= txtcontent.ClientID %>', { skin: 'kama' });
</script>(用ckfinder文件下skins文件下kama文件下的,skin.js,樣式)

Ⅵ java 如何利用ckeditor實現文件(html格式或者word格式)上傳並把文件中內容保存到資料庫中

打開:
將word在後台轉換為htm,將htm內容傳到前台,在editor內面通過html方式載入該內容。。。

保存:
將editor內容保存為htm文件,將htm文件轉化為doc。。。

Ⅶ ckeditor+ckfinder for java 的中文圖片無法顯示和中文文件夾亂碼問題

出現問題的原因是java代碼中獲取的中文字元串沒有定義編碼格式,讀取的時候是亂碼,所以顯示不出來。
獲取到的文件中通常都是「iso8859-1」格式,需要轉換為「UTF-8」格式。
如:String
str
=
new
String(str.getByte("iso8859-1"),"UTF-8");進行下強制轉換後在進行讀取即可。
通常格式有GBK、UTf-8、iso8859-1、GB2312,如果上面的強制轉換不成功,依次進行這些格式的嘗試,肯定是可以解決問題的。

Ⅷ ckeditor+ckfinder上傳圖片出錯問題

熱心網友
滾2012-12-10 18:47熱心網友

Ⅸ asp.net CKEditor + CKFinder控制項,上傳圖片提示「上傳文件已損失」!跪求答案!

  1. 檢查你的web.config是否允許上傳4M以上的大文件;

  2. 檢查你的上傳目錄文件夾是否允許IIS進行讀寫操作;

  3. 檢查CKEditor的js,允許上傳的最大文件大小。

熱點內容
python跨模塊 發布:2025-07-30 23:04:43 瀏覽:300
阿泰編程 發布:2025-07-30 21:36:05 瀏覽:569
mybatis註解sqlif 發布:2025-07-30 21:33:59 瀏覽:572
安卓手機為什麼削不短下巴 發布:2025-07-30 21:23:13 瀏覽:495
澳洲訪問學者簽證類型 發布:2025-07-30 20:55:12 瀏覽:354
svn切換伺服器ip 發布:2025-07-30 20:43:10 瀏覽:198
匯通啟富軟體如何修改登錄密碼 發布:2025-07-30 20:41:08 瀏覽:243
公共場所的wifi密碼名稱是什麼 發布:2025-07-30 20:19:56 瀏覽:636
ios系統怎麼解壓 發布:2025-07-30 20:14:05 瀏覽:740
sqlip 發布:2025-07-30 19:20:22 瀏覽:178