ckeditor编辑器上传附件

config.js

CKEDITOR.editorConfig = function( config ) { 
调用的action方法
config.filebrowserUploadUrl = 'vmscms/UpFj.action';   
    禁止标签选项卡 
config.removeDialogTabs = 'link:advanced;link:target;image:Upload;image:target;flash:Upload;flash:target;';
config.toolbar = 'Full'; config.toolbarStartupExpanded = false;   config.width='580px'; config.height='250px'; 
//默认工具栏 高级
config.toolbar_Full = [
{ name: 'document', items : [
'Source','-','NewPage','DocProps','Preview','Print','-','Templates' ] }, 
{ name: 'clipboard', items : [ 'Cut','Copy','Paste','PasteText','PasteFromWord','-','Undo','Redo' ] },
{ name: 'editing', items : [ 'Find','Replace','-','SelectAll','-','SpellChecker', 'Scayt' ] },'/',
{ name: 'forms', items : [ 'Form', 'Checkbox', 'Radio', 'TextField', 'Textarea', 'Select', 'Button', 'ImageButton', 'HiddenField' ] }, 
{ name: 'basicstyles', items : [ 'Bold','Italic','Underline','Strike','Subscript','Superscript','-','RemoveFormat' ] },
{ name: 'links', items : [ 'Link','Unlink','Anchor' ] },
{ name: 'paragraph', items : [ 'NumberedList','BulletedList','-','Outdent','Indent','-','Blockquote','CreateDiv', '-','JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock','-','BidiLtr','BidiRtl' ] }, 
{ name: 'insert', items : [ 'Image','Flash','Table','HorizontalRule','Smiley','SpecialChar','PageBreak','Iframe' ] }, '/',
{ name: 'styles', items : [ 'Styles','Format','Font','FontSize' ] },
{ name: 'colors', items : [ 'TextColor','BGColor' ] }, 
{ name: 'tools', items : [ 'Maximize', 'ShowBlocks','-','About' ] } ];
};   
配置上面的后 点击编辑器插入超链接


会出现上传选项卡。然后点击浏览上传附件点击上传到服务器上 会把路径返回回来 如下图。
把链接复制下来 点击超链接信息
把复制的链接粘贴到源文件文本框中,然后点击确定按钮。
编辑器中就会有刚才的路径 是链接形式。

后台 action

public String UpFj() {
PrintWriter out = null;
HttpServletResponse response = ServletActionContext.getResponse();
response.setContentType("text/html;charset=utf-8");
response.setCharacterEncoding("utf-8");
try {
out = response.getWriter();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
// 文件上传
if (upload != null) {
String up =
uploadFileName.substring(uploadFileName.lastIndexOf("."));

// 判断附件的格式
/* if (up.equalsIgnoreCase(".wps")) {
out.print("该功能不支持上传.wps");
return null; }*/
 

// 按照日期每天生成一个文件夹
String path = "/upload/cms/"
+ new SimpleDateFormat("yyyyMMdd").format(new Date());

// 判断文件夹是否存在
File destFile = new File(ServletActionContext.getServletContext()
.getRealPath("")
+ path);
if (!destFile.exists()) {
destFile.mkdir();
}

path = path + "/" + uploadFileName;
try {
FileUtils.copyFile(upload, new File(ServletActionContext
.getServletContext().getRealPath("")
+ path));
pathvalue = path.substring(1);
out.print(pathvalue);
} catch (IOException e) {
e.printStackTrace();
}finally {
out.flush();
out.close();
}

}
return null;
}  

在测试中 后台接收时只能用 upload 属性 wps上传过后在前台点击不支持下载和保存,直接打开后乱码!! 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值