kindeditor完美整合struts2实现图片上传的功能(二)

2014-11-24 00:07:40 · 作者: · 浏览: 1
e[] buffer = new byte[1024]; InputStream in = new FileInputStream(file); try { int num = 0; while ((num = in.read(buffer)) > 0) { fos.write(buffer, 0, num); } } catch (Exception e) { e.printStackTrace(System.err); } finally { try{ if(in != null) in.close(); if(fos != null) fos.close(); }catch(IOException e){} } JSONObject obj = new JSONObject(); obj.put("error", 0); obj.put("url", saveUrl); System.out.println(saveUrl); out.print(obj.toJSONString()); return null; } private String getError(String message) { JSONObject obj = new JSONObject(); obj.put("error", 1); obj.put("message", message); return obj.toJSONString(); } }
2.struts配置


  
			
		
  

3. jsp上的页面

<script src="kindeditor/lang/zh_CN.js">
		
		<script>
			var editor1;
			
			KindEditor.ready(function(K) {
				editor1 = K.create('textarea[name="content"]', {
					resizeType : 1,
					uploadJson : 'uploadimage',
					//uploadJson : 'kindeditor/jsp/upload_json.jsp',
					//fileManagerJson : 'kindeditor/jsp/file_manager_json.jsp',
					allowPreviewEmoticons : true,
					allowImageUpload : true,
					minWidth : '500px',
					items : [
						'source','wordpaste','preview',
						'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline',
						'removeformat', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist',
						'insertunorderedlist', '|', 'emoticons', 'image', 'link','baidumap']
				});
			});