Ckedit browse images and upload images

Source: Internet
Author: User


Introduced in

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

Config.js configuration file

Ckeditor.editorconfig = function (config) {//Define changes to the default configuration here. For example:config.language = ' ZH-CN '; Config.uicolor = ' #AADC6E '; Config.image_previewtext= ";       Preview area display Content Config.filebrowserwindowwidth = ' 440 ';    Config.filebrowserwindowheight = ' 500 ';    Config.filebrowserimageuploadurl = ' upload.action ';      Defines the image upload action Config.filebrowserimagebrowseurl = ' browse.action?type=images '; Defines the page that browses the server picture};


Browse Server Picture page code browse.jsp:

<%@ page language= "java"  contenttype= "Text/html; charset=utf-8"  pageEncoding= " UTF-8 "%><% @page  import=" Java.io.File "%><script type=" text/javascript "> //This function is the focus , or you can't interact with CKEditor.  function funcallback (Funcnum, fileurl)  {  var  parentwindow =  (Window.parent == window)  ? window.opener     :  window.parent;  parentwindow.ckeditor.tools.callfunction (Funcnum, fileurl);   Window.close (); }</script><div> <%  string path =  Request.getcontextpath ()  +  "/";  string type =  "";  if  ( Request.getparameter ("type")  != null)//Get file Classification              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 (" ")    }  } else {   out.println (" 



Strut.xml Configuration

<!--ckeditor Browse and upload pictures-<action name= "Browse" class= "noticeaction" method= "browse" > <result name= "succ ESS ">/ckeditor/uploader/browse.jsp</result> </action>

Backstage code, the background action does not do the processing, jumps directly to the browse.jsp page

CKEditor upload pictures and browse pictures public String browse () {System.out.println (This.getrequest (). Getcontextpath ());   System.out.println (Servletactioncontext.getservletcontext (). Getrealpath ("ckeditor/uploader/upload/"));     return SUCCESS; }

Actual results such as:


650) this.width=650; "title=" capture. PNG "alt=" wkiol1xdbtaxuiaaaala2uet5bs475.jpg "src=" http://s3.51cto.com/wyfs02/M02/70/FD/ Wkiol1xdbtaxuiaaaala2uet5bs475.jpg "/>


Upload Image Action Code:


    private file upload;      private string  uploadContentType;                private String uploadFileName;           Private string ckeditorfuncnum;   public string upload () {    String destpath = servletactioncontext.getservletcontext (). Getrealpath ("ckeditor/uploader/ Upload/images/");    system.out.println (destpath);    file file=new file (DestPath);    if (!file.exists ())  file.mkdirs ();    system.out.println (file);          try {                     system.out.println ( Uploadfilename);            string uuid = uuid.randomuuid (). toString ();                       string rt[] = uploadfilename.split ("\ \");                    System.out.println (rt[1]);                   uploadfilename = new string (uuid+ ".") +RT[1]);//solve the problem of server error when uploading the Chinese path of image.          fileutils.copyfile (Upload, new file (File, Uploadfilename));                  printwriter out = servletactioncontext.getresponse (). GetWriter ();          out.write ("<script type= ' Text/javAscript ' >window.parent.ckeditor.tools.callfunction ("+ckeditorfuncnum+",  '/admin/ckeditor/uploader/ Upload/images/"              +  uploadfilename             +  "',  ' );</script> ");                   } catch  (ioexception e)  {    e.printstacktrace ();    }   return action.none;     }


Strut.xml Configuration without result

<action name= "Upload" class= "noticeaction" method= "Upload" > </action>


650) this.width=650; "title=" Capture 1. PNG "src=" http://s3.51cto.com/wyfs02/M02/71/02/wKiom1XDGqPinC5zAAHn2x6_5pU195.jpg "alt=" wkiom1xdgqpinc5zaahn2x6_ 5pu195.jpg "/>

Reference article:

http://blog.csdn.net/mamba10/article/details/8543219

In this article out.write write the picture path when there is less than an application name Admin (your Web project deployed under the server application name), we should pay attention to

This article is from the "Nothing-skywalker" blog, please be sure to keep this source http://tianxingzhe.blog.51cto.com/3390077/1682293

Ckedit browse images and upload images

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.