#스마트에디터 장착하기, #Spring, #Jsp, #Java, #위지윅, #에디터
마스터욱
0
217
0
0
2017-03-08 14:42:30
그리 어렵지는 않다라고 하면서 하루종일 삽질했음...
Controller 소스부분 구현이 제일 난관이였습니다.
파일업로드 JSP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <script type="text/javascript" src="../plugin/smarteditor/js/HuskyEZCreator.js" charset="utf-8"></script> <script type="text/javascript"> var EditorObj = []; //전역변수 $(document).ready(function(){ //스마트에디터 프레임생성 nhn.husky.EZCreator.createInIFrame({ oAppRef: EditorObj, elPlaceHolder: "editor", sSkinURI: "../plugin/smarteditor/SmartEditor2Skin.html", htParams : { // 툴바 사용 여부 (true:사용/ false:사용하지 않음) bUseToolbar : true, // 입력창 크기 조절바 사용 여부 (true:사용/ false:사용하지 않음) bUseVerticalResizer : true, // 모드 탭(Editor | HTML | TEXT) 사용 여부 (true:사용/ false:사용하지 않음) bUseModeChanger : true, } }); $("#noticeForm").validate({ rules : { title : { required : true, minlength : 1, maxlength : 255 }, content : { required : true, minlength : 8, maxlength : 20 } }, messages : { title : { required : '제목을 입력해주세요.' }, content : { required : '내용을 입력해주세요.' } }, errorClass : "form-invalid", submitHandler : function(form){ EditorObj.getById["editor"].exec("UPDATE_CONTENTS_FIELD", []); //console.log($("#editor").val()); form.submit(); } }); }); </script> <h3 class="sub-header">공지사항</h3> <form id="noticeForm" name="noticeForm" class="form-horizontal" method="post" enctype="multipart/form-data" action='noticeSave'> <div class="form-group"> <div class="col-sm-12"> <input type="text" class="form-control" id="title" name="title" placeholder="제목을 입력해주세요."> </div> </div> <div class="form-group"> <div class="col-sm-12"> <input type="file" class="form-control" id="file" placeholder="첨부파일을 넣어주세요."> </div> </div> <div class="form-group"> <div class="col-sm-12"> <textarea id="editor" name="content" style="width:100%;height:500px;"></textarea> </div> </div> <div class="form-group"> <div class="col-sm-12"> <button type="submit" class="btn btn-primary">저장</button> </div> </div> </form> | cs |
파일업로드 Controller
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | @RequestMapping(value="/photoUpload", method=RequestMethod.POST) public @ResponseBody String photoUpload(MultipartHttpServletRequest request, HttpServletResponse response, Model model){ System.out.println("photoUpload controller"); try { Iterator<String> itr = request.getFileNames(); MultipartFile mpf; while (itr.hasNext()) { mpf = request.getFile(itr.next()); System.out.println(mpf.getOriginalFilename()); String filename = mpf.getOriginalFilename(); String filename_ext = filename.substring(filename.lastIndexOf(".")+1); filename_ext = filename_ext.toLowerCase(); String dftFilePath = request.getSession().getServletContext().getRealPath("/"); //파일 기본경로 _ 상세경로 SimpleDateFormat formatter = new SimpleDateFormat("yyyyMM"); String folderName = formatter.format(new java.util.Date()); String filePath = dftFilePath + "images" + File.separator + "photoUpload" + File.separator + folderName + File.separator; //C:\Users\wook\Desktop\eGov\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\BizV3\images\photo_upload\201703 System.out.println("filePath = " + filePath); String realFileNm = ""; formatter = new SimpleDateFormat("yyyyMMddHHmmss"); String today= formatter.format(new java.util.Date()); realFileNm = today+UUID.randomUUID().toString() + filename.substring(filename.lastIndexOf(".")); String rlFileNm = filePath + realFileNm; //C:\Users\wook\Desktop\eGov\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\BizV3\images\photo_upload\201703\2017030809570465a56af2-b3d6-4283-a0ae-1f0b19434864.jpg System.out.println("rlFileNm = " + rlFileNm); try { File file = new File(rlFileNm); if(!file.exists()) { file.mkdirs(); } mpf.transferTo(file); } catch (IOException e) { e.printStackTrace(); } String json = ""; json += "{\"files\":[{"; json += "\"name\":\""+realFileNm+"\","; json += "\"url\":\""+request.getContextPath()+"/images/photoUpload/"+folderName+"/"+realFileNm+"\""; /* json += "\"width\":\"500\","; json += "\"height\":\"749\""; json += "\"oriname\":\"b9548a3f8c02df7d3e95074e2df979b7.jpg\","; json += "\"size\":183397,"; json += "\"type\":\"image\/jpeg\","; json += "\"deleteUrl\":\"http:\/\/story84.com\/plugin\/smarteditor\/photo_uploader\/popup2\/php\/?file=9a3ddde7401c4c064b7277a021b669fd_1488939962_4608.jpg\","; json += "\"deleteType\":\"DELETE\""; */ json += "}]}"; return json; } } catch (Exception e) { e.printStackTrace(); } return ""; } | cs |