当前位置:编程学习 > JSP >>

java中KindEditor本地图片上传与上传失败问题


{"error":0,"message":".....","url":"/img/1111.gif"}
其中当error值为0时表示上传成功,需要指定url值为图片保存后的URL地址,如果error值不为0,则设置message值为错误提示信息


首先指定上传处理的URI

 代码如下 复制代码

KE.show({
 id : 'ta_blog_content',
 resizeMode : 1,
 shadowMode : false,
 allowPreviewEmoticons : false,
 urlType : 'absolute',
 allowUpload : true, //允许上传图片
 imageUploadJson : '/action/blog/upload_img' //服务端上传图片处理URI
});

图片上传处理方法

 代码如下 复制代码

/**
 * 图片上传
 * @param ctx
 * @throws IOException
 */
@Annotation.PostMethod
@Annotation.JSONOutputEnabled
public void upload_img(RequestContext ctx) throws IOException {
 File imgFile = ctx.image("imgFile");
 if(imgFile.length() > MAX_IMG_SIZE ){
  ctx.output_json(
   new String[]{"error","message"},
   new Object[]{1,ResourceUtils.getString("error", "file_too_large", MAX_IMG_SIZE/1024)}
  );
  return ;
 }
 String uri = new SimpleDateFormat("yyyyMMdd").format(new Date())
  + "/IMG_"
  + RandomStringUtils.randomAlphanumeric(4)
  + '_'
  + String.valueOf(ctx.user().getId())
  + '.'
  + FilenameUtils.getExtension(imgFile.getName()).toLowerCase();

 Multimedia.saveImage(imgFile, img_path + uri, 0, 0);
 ctx.output_json(new String[]{"error","url"}, new Object[]{0, LinkTool.upload("space/"+uri)});
}

kindeditor上传本地图片的问题 .

现kindeditor上传本地图片时,为什么出现服务器错误

 原来demo.jsp里的:

 代码如下 复制代码
       
KE.show({
   id : 'content1',
   imageUploadJson : '../../jsp/upload_json.jsp',
   fileManagerJson : '../../jsp/file_manager_json.jsp', 为什么要返回两级文件夹呢?(”../“代表返回一级文件夹)
   allowFileManager : true,
   afterCreate : function(id) {
    KE.event.ctrl(document, 13, function() {
     KE.util.setData(id);
     document.forms['example'].submit();
    });
    KE.event.ctrl(KE.g[id].iframeDoc, 13, function() {
     KE.util.setData(id);
     document.forms['example'].submit();
    });
   }
  });

 原来是因为imageUploadJson 这个JSON值是传到plugins下的image文件夹里。于是,要找到upload_json.jsp,则要返回到根目录,即返回两层菜单。好了,终于解决了,明天就开始移植到文章发布系统了,终于可以睡了

补充:Jsp教程,Java技巧及代码 
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,