网络查找的资料都是说Ckeditor是Fckeditor的升级,虽然它的界面比较的漂亮,但是有些功能必须要另外的添加,例如上传功能,我在网上查找了很多资料后,才找了这个比较好的,所以和大家分享一下。
程序的结构图
在index.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="ckeditor/ckeditor.js"></script>
<script type="text/javascript">
window.onload = function() {
CKEDITOR.replace('editor');
};
</script>
</head>
<body>
<form action="ShowServlet" method="post">
<textarea rows="" cols="" name="editor"></textarea>
<br /> <input type="submit" value="提交"><input type="reset">
</form>
</body>
</html>
上传的操作页面
browse.jsp
<%@page import="java.io.File"%>
<%@ page language="java" contentType="text/html; charset=GB18030"
pageEncoding="GB18030"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB18030">
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<title>图片浏览</title>
<script type="text/javascript">
//这段函数是重点,不然不能和CKEditor互动了
function funCallback(funcNum, fileUrl) {
var parentWindow = (window.parent == window) ? window.opener
: window.parent;
parentWindow.CKEDITOR.tools.callFunction(funcNum, fileUrl);
window.close();
}
</script>
</head>
<body>
<%
String path = request.getContextPath() + "/";
String type = "";
if (request.getParameter("type") != null)//获取文件分类
type = request.getParameter("type").toLowerCase() + "/";
String clientPath = "ckeditor/uploader/upload/" + type;
File root = new File(request.getSession().getServletContext()
.getRealPath(clientPath));
if (!root.exists()) {
root.mkdirs();
}
String callback = request.getParameter("CKEditorFuncNum");
File[] files = root.listFiles();
if (files.length > 0) {
for (File file : files) {
String src = path + clientPath + file.getName();
out.println("<img width='110px' height='70px' src='" + src
+ "' alt='" + file.getName()
+ "' onclick=\"funCallback(" + callback + ",'"
+ src + "')\">");
}
} else {
out.println("<h3>未检测到资源。</h3>");
}
%>
</body>
</html>
upload.jsp
<%@page import="java.io.File"%>
<%@page import="java.util.UUID"%>
<%@page import="org.apache.commons.fileupload.FileItem"%>
<%@page import="java.util.List"%>
<%@page import="org.apache.commons.fileupload.disk.DiskFileItemFactory"%>
<%@page import="org.apache.commons.fileupload.FileItemFactory"%>
<%@page import="org.apache.commons.fileupload.servlet.ServletFileUpload"%>
<%@ page language="java" contentType="text/html; charset=GB18030"
pageEncoding="GB18030"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB18030">
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<title>JSP上传文件</title>
</head>
<body>
<%
String path = request.getContextPath() + "/";
if (ServletFileUpload.isMultipartContent(request)) {
String type = "";
if (request.getParameter("type") != null)//获取文件分类
type = request.getParameter("type").toLowerCase() + "/";
String callback = request.getParameter("CKEditorFuncNum");//获取回调JS的函数Num
FileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload servletFileUpload = new ServletFileUpload(
factory);
servletFileUpload.setHeaderEncoding("UTF-8");//解决文件名乱码的问题
List<FileItem> fileItemsList = servletFileUpload
.parseRequest(request);
for (FileItem item : fileItemsList) {
if (!item.isFormField()) {
String fileName = item.getName();
fileName = "file" + System.currentTimeMillis()
+ fileName.substring(fileName.lastIndexOf("."));
//定义文件路径,根据你的文件夹结构,可能需要做修改
String clientPath = "ckeditor/uploader/upload/" + type
+ fileName;
//保存文件到服务器上
File file = new File(request.getSession()
.getServletContext().getRealPath(clientPath));
if (!file.getParentFile().exists()) {
file.getParentFile().mkdirs();
}
item.write(file);
//打印一段JS,调用parent页面的CKEditor的函数,传递函数编号和上传后文件的路径;这句很重要,成败在此一句
out.println("<script type='text/javascript'>window.parent.CKEDITOR.tools.callFunction("
+ callback
+ ",'"
+ path
+ clientPath
+ "')</script>");
break;
}
}
}
%>
</body>
</html>
config.js
/*
* Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see LICENSE.html or http://ckeditor.com/license
*/
CKEDITOR.editorConfig = function(config) {
// Define changes to default configuration here. For example:
// config.language = 'fr';
// config.uiColor = '#AADC6E';
config.language = 'zh-cn';
config.filebrowserBrowseUrl = 'ckeditor/uploader/browse.jsp';
config.filebrowserImageBrowseUrl = 'ckeditor/uploader/browse.jsp?type=Images';
config.filebrowserFlashBrowseUrl = 'ckeditor/uploader/browse.jsp?type=Flashs';
config.filebrowserUploadUrl = 'ckeditor/uploader/upload.jsp';
config.filebrowserImageUploadUrl = 'ckeditor/uploader/upload.jsp?type=Images';
config.filebrowserFlashUploadUrl = 'ckeditor/uploader/upload.jsp?type=Flashs';
config.filebrowserWindowWidth = '640';
config.filebrowserWindowHeight = '480';
config.toolbar_A = [
['Source'],
['Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', '-',
'Print', 'SpellChecker', 'Scayt'],
['Undo', 'Redo', '-', 'Find', 'Replace', '-', 'SelectAll',
'RemoveFormat'],
'/',
['Bold', 'Italic', 'Underline', 'Strike', '-', 'Subscript',
'Superscript'],
['NumberedList', 'BulletedList', '-', 'Outdent', 'Indent',
'Blockquote'],
['JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock'],
['Link', 'Unlink', 'Anchor'],
['Image', 'Flash', 'Table', 'HorizontalRule', 'Smiley',
'SpecialChar', 'PageBreak'], '/',
['Styles', 'Format', 'Font', 'FontSize'], ['TextColor', 'BGColor'],
['Maximize', 'ShowBlocks']];
config.toolbar = 'A';
};
所使用的源码,被打包成压缩包
- 大小: 20.5 KB
分享到:
相关推荐
可以实现网络上传功能但是从官网上下载的没有上传图标,只能写地址,很不方便,这里增加了js代码来实现上传功能
CKEditor 5 视频功能 该包实现了 CKEditor 5 的视频功能。该功能以由几个插件实现的粒度形式引入。 它的灵感来自 ckeditor5-image 包。演示参见sample/app.js文档安装将此添加到您的自定义构建或您的项目中。 使用 ...
#flask-ckeditor-demo
Flask项目——集成富文本编辑器CKeditor,实现了图片上传、文件上传、Flash上传等功能。方便进行项目集成及应用。代码无需任何修改,可完美执行!!! Flask项目——集成富文本编辑器CKeditor,实现了图片上传、...
ckfinder java使用 富文本编辑框 CKEditor和CKFinder整合实现上传下载功能 可以直接导入使用 整合参考资料: http://guoliang0-0-yahoo-cn.iteye.com/blog/1195348
CKEditor实现本地视频和图片的上传功能,不用kfinal
Ckeditor上传图片!本身Ckeditor不具备上传图片功能的!前两天在一个博客园的一个博主那里讨了点Ckeditor上传图片的方法,现在共享给大家!博主的博客地址和实现方式我压缩在文件中了!大家支持正版哈!
JAVA工程项目整合ckeditor+ckfinder实现图片上传、文件上传功能。
ckeditor文件上传功能,附图片上传示例,java程序及返回结果。 strut配置 <param name="allowedTypes">image/bmp||image/png||image/gif||image/jpeg||image/jpg||image/pjpeg</param> ...
java与ckeditor和ckfinder整合后实现上传图片功能
利用jsp实现ckeditor_3_6_2 上传图片功能,里面包含完整的工程,不过需要自己引入commons-fileupload-1.2.1.jar,commons-io-1.4.jar文件上传包,网上一大把。只要能正确引入,该工程就能完成
用webupload插件,自定义ckeditor按钮控件,实现文件上传功能,包括后台接口ashx文件。
第一步:网站需要引用CKFinder的dll(目录:/CKFinder/bin/Release/CKFinder....配置完成后CKEditor 就带有上传功能了,但假如上传图片时,图片的文件是用原来图片的名字,想改为随机文件名呢,怎么办?接着看第三步。
Ckeditor在线编辑器,实现了图片上传功能,直接就能用的...
ckeditor与ckfinder(java版)整合详细流程 实现了图片的上传功能
NULL 博文链接:https://sarin.iteye.com/blog/599499
使用java语言struts技术实现富文本编辑器的图片上传功能
主要为大家详细介绍了CKEditor与dotnetcore实现图片上传功能,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
在项目中我们使用了FckEditor,但最新又出来了个ckEditor,到官方网站看看才知道FckEditor在2.6版本...配置简单的编辑器很简单,我们下载ckEditor就可以使用,我想大多数人都希望能用到编辑器里的浏览/插入图片功能吧。