将上面的下载好的demo放入所需的项目工程中去
在需要引入富文本编辑器的地方加上这段代码
Ckeditor编辑器上传图片
/**
ckeditor图片上传
@Title imageUpload
@param request
@param response
*/
@RequestMapping(value="/admin/imageUpload", method=RequestMethod.POST)
public void imageUpload(HttpServletRequest request, HttpServletResponse response) {
String DirectoryName = “upload/article”;
String relativePath = env.getProperty(“image.file.article.dir”);
System.out.println(“relativePath=========”+relativePath);
try {
ImageUploadUtil.ckeditor(request, response, DirectoryName,relativePath);
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
Controller 层spring MVC
/**
ckeditor文件上传功能,回调,传回图片路径,实现预览效果。
@Title ckeditor
@param request
@param response
@param DirectoryName
文件上传目录:比如upload(无需带前面的/) upload/…
@throws IOException
*/
public static void ckeditor(HttpServletRequest request, HttpServletResponse response, String DirectoryName,String relativePath)
throws IOException {
String fileName = upload(request, DirectoryName,relativePath);
// 结合ckeditor功能
// imageContextPath为图片在服务器地址,如upload/123.jpg,非绝对路径
String imageContextPath = request.getContextPath() + “/” + DirectoryName + “/” + fileName;
response.setContentType(“text/html;charset=UTF-8”);
String callback = request.getParameter(“CKEditorFuncNum”);
PrintWriter out = response.getWriter();
out.println("