springMvc+Kindeditor整合
来源:互联网 发布:linux vi编辑器例题 编辑:程序博客网 时间:2024/04/28 21:46
@RequestMapping(value = "/Kindeditor/uploadFile", method = RequestMethod.POST)public void uploadFile(HttpServletRequest request, HttpServletResponse response) throws Exception {PrintWriter writer = response.getWriter();try {// 文件保存目录路径String savePath = request.getSession().getServletContext().getRealPath("/") + "upload" + File.separatorChar+ "products" + File.separatorChar;String saveUrl = request.getContextPath()+ File.separatorChar + "upload" + File.separatorChar+ "products" + File.separatorChar;// 定义允许上传的文件扩展名HashMap<String, String> extMap = new HashMap<String, String>();extMap.put("image", "gif,jpg,jpeg,png,bmp");// 最大文件大小long maxSize = 1000000;response.setContentType("text/html; charset=UTF-8");if (!ServletFileUpload.isMultipartContent(request)) {writer.println(getError("请选择文件。"));return;}File uploadDir = new File(savePath);// 判断文件夹是否存在,如果不存在则创建文件夹if (!uploadDir.exists()) {uploadDir.mkdirs();}// 检查目录写权限if (!uploadDir.canWrite()) {writer.println(getError("上传目录没有写权限。"));return;}String dirName = request.getParameter("dir");if (dirName == null) {dirName = "image";}if (!extMap.containsKey(dirName)) {writer.println(getError("目录名不正确。"));return;}MultipartHttpServletRequest mRequest = (MultipartHttpServletRequest) request;Map<String, MultipartFile> fileMap = mRequest.getFileMap();String fileName = null;for (Iterator<Map.Entry<String, MultipartFile>> it = fileMap.entrySet().iterator(); it.hasNext();) {Map.Entry<String, MultipartFile> entry = it.next();MultipartFile mFile = entry.getValue();fileName = mFile.getOriginalFilename();// 检查文件大小if (mFile.getSize() > maxSize) {writer.println(getError("上传文件大小超过限制。"));return;}String fileExt = fileName.substring(fileName.lastIndexOf(".")+1);if (!Arrays.<String> asList(extMap.get(dirName).split(",")).contains(fileExt)) {writer.println(getError("上传文件扩展名是不允许的扩展名。\n只允许" + extMap.get(dirName) + "格式。"));return;} UUID uuid = UUID.randomUUID(); String path = savePath + uuid.toString() +"."+ fileExt; saveUrl = saveUrl + uuid.toString() +"."+ fileExt;BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(path));FileCopyUtils.copy(mFile.getInputStream(), outputStream);JSONObject obj = new JSONObject();obj.put("error", 0);obj.put("url", saveUrl);writer.println(obj.toString());}} catch (ServiceException serviceException) {writer.println(getError(ApplicationContextUtil.getMessage(serviceException)));return;}}private String getError(String message) {JSONObject obj = new JSONObject();obj.put("error", 1);obj.put("message", message);return obj.toString();}
<link rel="stylesheet" href="<c:url value='/scripts/kindeditor/themes/default/default.css'/>" type="text/css"/><link rel="stylesheet" href="<c:url value='/scripts/kindeditor/plugins/code/prettify.css'/>" type="text/css"/><script charset="utf-8" src="<c:url value='/scripts/kindeditor/kindeditor-all.js'/>" type="text/javascript"></script><script charset="utf-8" src="<c:url value='/scripts/kindeditor/lang/zh-CN.js'/>" type="text/javascript"></script><script charset="utf-8" src="<c:url value='/scripts/kindeditor/plugins/code/prettify.js'/>" type="text/javascript"></script>
<form:textarea path="esCfgProduct.introduction" id="introduction" cssStyle="width:700px;height:300px;"/>
KindEditor.ready(function(K) { var introduction = K.create('#introduction',{ items:[ 'source', '|', 'undo', 'redo', '|', 'preview', 'print', 'template', 'code', 'cut', 'copy', 'paste', 'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright', 'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript', 'superscript', 'clearhtml', 'quickformat', 'selectall', '|', 'fullscreen', '/', 'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'image', 'multiimage', 'table', 'hr', 'emoticons', 'pagebreak', 'anchor', 'link', 'unlink', '|', 'about' ], uploadJson : '${ctx}/backoffice/Kindeditor/uploadFile.do', afterCreate : function() {var self = this;K.ctrl(document, 13, function() {self.sync();document.forms['inputForm'].submit();});K.ctrl(self.edit.doc, 13, function() {self.sync();document.forms['inputForm'].submit();});}}); <span style="white-space:pre">introduction.readonly();</span>//只读});
0 0
- springMvc+Kindeditor整合
- SpringMVC整合KindEditor,实现图片上传、预览、删除
- struts2与kindeditor整合
- EasyUI+Struts2整合KindEditor
- EasyUI+Struts2整合KindEditor
- kindeditor+struts2 整合
- Yii KindEditor整合
- kindeditor整合到dwz
- extjs mvc 整合kindeditor
- struts2整合kindeditor有感
- spring-boot整合kindeditor
- struts2与kindeditor整合
- springmvc+kindeditor使用
- Thinkphp+EasyUI Layout + kindeditor整合
- thinkphp整合kindeditor编辑器详解
- Struts2+Kindeditor整合图片上传
- springMVC+freemarker运行KindEditor插件
- SpringMVC下的kindeditor实现
- iOS中使用UITextView时候的一些小技巧
- 我这里有语法糖噢。叔叔,我们不约
- JBPM4.4工作流引擎学习(四)--流程资源RepositoryService
- Cadence基础知识5(allegro中如何添加安装孔(注:在PCB图纸中添加) )
- 超速学习理论与方法实践
- springMvc+Kindeditor整合
- Sonar简介
- linux 技巧:使用 screen 管理你的远程会话
- MongoDB发生Can't take a write lock while out of disk space错误解决方法
- 浅谈ImageList。。。
- Android ViewPager使用详解,加载几个简单布局案例+代码
- freemaker list 序号
- iOS动态增加属性
- #include <stdio.h>