1.引入资源

<script type="text/javascript" src="${ctx}/ckeditor/ckeditor.js"></script>

2.显示UI

<textarea id="content"></textarea> <script type="text/javascript"> CKEDITOR.replace('content'); </script>

3.下载设置 1.打开下载选项卡

ckeditor/plugins/image/dialogs/image.js


2.去掉文字提示

ckeditor/plugins/image/dialogs/image.js


3.创建后台接收Action

@Controller @Scope("prototype") public class CkeditorAction extends BaseAction { private File upload; private String uploadFileName; private String uploadContentType; //配置set方法------------------------------------------------------ /** * 处理ckeditor的文件上传请求 * **/ public String uploadFile(){ //获得客户端会调的函数 String callback=ServletActionContext.getRequest().getParameter("CKEditorFuncNum"); try{ String ext=uploadFileName.substring(uploadFileName.lastIndexOf(".")); String newName=UUID.randomUUID().toString().replace("-","")+ext; //获得服务器上目录的绝对路径 String path=ServletActionContext.getServletContext().getRealPath("/upload"); //创建File对象 File file=new File(path,newName); //将上传的文件保存到服务器的目录下 FileUtils.copyFile(upload,file); String uri="upload/"+newName;

       StringBuffer sb=new StringBuffer();
       sb.append("<script type=\"text/javascript\">");
       sb.append("window.parent.CKEDITOR.tools.callFunction("+callback+",'"+uri+"','');");
       sb.append("</script>");

       //this.inputStream=new ByteArrayInputStream(sb.toString().getBytes());
       ServletActionContext.getResponse().getWriter().write(sb.toString());
   }catch(Exception ex){
       ex.printStackTrace();
   }
   return null;
}

}

4.配置处理文件上传的URL