CKEditor 사용 및 파일 업로드 적용

1. CKEditor 다운

 

- DOWNLOAD URL

http://ckeditor.com/ 에서 다운로드

 

- 설치 위치

webapp 밑에 copy

 

- JSP 설정

<script src="${pageContext.request.contextPath}/js/ckeditor/ckeditor.js"></script>

 

<textarea name="contents" id="contents" rows="50" cols="10">

                

</textarea>

<script>

// Replace the <textarea id="editor1"> with a CKEditor

// instance, using default configuration.

CKEDITOR.replace( 'contents', {

filebrowserUploadUrl: '${pageContext.request.contextPath}/file/ckeditorImageUpload.do'

});

</script>

 

filebrowserUploadUrl 을 설정을 해주어야 사진 업로드 시 업로드 탭이 생겨 사진파일을 업로드 할 수 있다.

그렇지 않으면 CKFinder를 사용하여 적용 시켜주어야 한다.

 

- 사진 업로드 구현 Servlet

Controller

@RequestMapping(value="/file/ckeditorImageUpload.do", method=RequestMethod.POST)

public void ckeditorImageUpload(HttpServletRequest request, HttpServletResponse response, @RequestParam MultipartFile upload) throws     Exception {

 

response.setCharacterEncoding("UTF-8");

response.setContentType("text/html;charset-utf-8");

 

try {

경축! 아무것도 안하여 에스천사게임즈가 새로운 모습으로 재오픈 하였습니다.
어린이용이며, 설치가 필요없는 브라우저 게임입니다.
https://s1004games.com

fileService.ckeditorImageUpload(request, response, upload);

 

} catch (IOException e) {

e.printStackTrace();

}

}

 

Service Impl

@SuppressWarnings("resource")

public void ckeditorImageUpload(HttpServletRequest request, HttpServletResponse response, MultipartFile file) throws Exception {

OutputStream out = null;

PrintWriter printWriter = null;

String fileName = file.getOriginalFilename();

byte[] bytes = file.getBytes();

String uploadPath = FILE_URL + "\" + fileName;

 

System.out.println(uploadPath);

out = new FileOutputStream(new File(uploadPath));

out.write(bytes);

String callback = request.getParameter("CKEditorFuncNum");

 

printWriter = response.getWriter();

String fileUrl = request.getContextPath()+SAVE_URL + "/" +fileName; //url 경로

 

printWriter.println("<script type='text/javascript'>window.parent.CKEDITOR.tools.callFunction("

               + callback

               + ",'"

               + fileUrl

               + "','이미지를 업로드 하였습니다.'"

               + ")</script>");

       printWriter.flush();

}

 



출처: http://hybrid1006.tistory.com/entry/CKEditor-사용-및-파일-업로드-적용 [soft program]

 

본 웹사이트는 광고를 포함하고 있습니다.
광고 클릭에서 발생하는 수익금은 모두 웹사이트 서버의 유지 및 관리, 그리고 기술 콘텐츠 향상을 위해 쓰여집니다.
번호 제목 글쓴이 날짜 조회 수
106 Spring MVC Dropdown Box Example file 졸리운_곰 2018.03.26 188
105 SpringBoot JPA 예제 졸리운_곰 2018.03.13 304
104 스프링 CKEditor 적용 - 에디터 졸리운_곰 2018.03.07 2555
103 spring ckeditor 파일업로드 예제 (file upload) file 졸리운_곰 2018.03.07 1996
» CKEditor 사용 및 파일 업로드 적용 졸리운_곰 2018.03.07 119
101 Spring MVC Checkbox And Checkboxes Example 자바 스프링 mvc 체크박스 샘플 file 졸리운_곰 2018.03.07 50
100 SPRING MVC - CHECKBOXES EXAMPLE 자바 스프링 mvc 체크박스 예제 file 졸리운_곰 2018.03.07 147
99 Spring MVC Dropdown Box Example 스프링 웹 개발 [콤보 선택 박스] file 졸리운_곰 2018.03.07 217
98 SPRING과 ANGULAR2 연동해서 실행하기 file 졸리운_곰 2018.02.12 163
97 두번째, 스프링 배치보다 간편한 스프링 Quartz 졸리운_곰 2018.02.08 74
96 첫번째, 스프링 배치보다 간편한 스프링 Quartz 졸리운_곰 2018.02.08 72
95 JAVA] Quartz (쿼츠)를 사용하여 자바 스케줄링(scheduling) 하기 졸리운_곰 2018.02.08 577
94 Spring Batch를 이용한 기본적인 Batch Application 졸리운_곰 2018.02.08 43
93 Quartz + Spring Batch 조합하기 file 졸리운_곰 2018.02.08 1930
92 스프링 web MVC와 앵귤러의 통합 How to configure AngularJs with Spring MVC | SpringBoot file 졸리운_곰 2018.01.28 156
91 스프링 부트와 앵귤러의 통합 : Spring Boot and AngularJS Integration Tutorial file 졸리운_곰 2018.01.28 451
90 mybatis에서 selectKey 사용법 졸리운_곰 2018.01.24 352
89 Spring form:form 태그 설명 졸리운_곰 2018.01.24 158
88 java spring form 태그 졸리운_곰 2018.01.24 114
87 Spring MVC - 값 전달 file 졸리운_곰 2018.01.24 39
대표 김성준 주소 : 경기 용인 분당수지 U타워 등록번호 : 142-07-27414
통신판매업 신고 : 제2012-용인수지-0185호 출판업 신고 : 수지구청 제 123호 개인정보보호최고책임자 : 김성준 sjkim70@stechstar.com
대표전화 : 010-4589-2193 [fax] 02-6280-1294 COPYRIGHT(C) stechstar.com ALL RIGHTS RESERVED