首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用ck上传图片

使用ck上传图片
EN

Stack Overflow用户
提问于 2012-06-14 14:19:00
回答 1查看 2.3K关注 0票数 0

我需要上传一个图像到服务器使用发送到服务器按钮在ck编辑器,并显示在ckeditor编辑区域的图像。在ckeditor中执行所有这些操作,如下所示,

url : b.config.filebrowserImageBrowseLinkUrl下面的代码在image.js中设置了hidden=false;

代码语言:javascript
复制
CKEDITOR.editorConfig = function( config )
{
    config.filebrowserUploadUrl = '../ckeditorImage.jsp';
}

ckeditorImage.jsp is like this


try{

    String boundary="";
    String sz="";
    String fname="",sem="",sub="",mod="",empid="";
    Enumeration enum1 = request.getHeaderNames();
    while(enum1.hasMoreElements())
    {
            String header = (String)enum1.nextElement();
            String hvalue = request.getHeader(header);
            if("content-length".equalsIgnoreCase(header) )
        sz=""+hvalue;

    } 
        ServletInputStream sv=request.getInputStream();       
    int ch=0;
    String val="";  
    while((ch=sv.read())!=-1)
    {
        val+=(char)ch;      
                if(val.indexOf("Content-Type: ")>=0)
        {

            String tp="Content-Type: ";

            fname=val.substring(val.indexOf("filename=")+"filename=".length(),val.indexOf(tp));
                        fname=fname.replace('"',' ');
                        System.out.println(" =======fname============    :"+fname);           
            fname="home1.jpg";                  
            long size = fname.length();         

                        while((ch=sv.read())!='\n');
            byte[] b=new byte[Integer.parseInt(sz)];
            int cntr=0;
            while(cntr<b.length)
            {
                b[cntr]=(byte)sv.read();
                cntr++;
            }
                        String str=new String(b);
            int pos=str.indexOf(boundary)-2;
            pos=b.length;
            System.out.println(" =======fname============    :"+fname);  
                         File f=new File(config.getServletContext().getRealPath("/")+"/images/"+fname);
                         System.out.println(" creation of directory"+config.getServletContext().getRealPath("/")+"/images/"+fname);
                         System.out.println(" creation");
                       /*  if(f.isDirectory())
                         {
                             String fl[]=f.list();

                             for(int i=0;i<fl.length;i++)
                                 {
                                  File fd=new File(config.getServletContext().getRealPath("/")+"/users/"+sd+"/photos/"+fl[i]);
                                  fd.delete();
                             }
                         }*/
            if(!f.exists())
                f.mkdirs();
                         System.out.println(" creation of directory");
            java.io.FileOutputStream fout=new java.io.FileOutputStream(config.getServletContext().getRealPath("/")+"/images/"+fname);

            fout.write(b,2,pos-4);
            System.out.println(" creation of directory"+fout);
            fout.close();
        }
    }
    }
    catch(Exception e)
    {
        out.println(e);
    }
EN

回答 1

Stack Overflow用户

发布于 2012-06-14 14:55:30

该项目还为您提供了CKEditor的文件浏览器。

http://sourceforge.net/projects/jckconnector/

如果您只需要上传部分,那么可以查看servlet代码

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11027677

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档