메뉴 건너뛰기

조회 수 3165 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄

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 {


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();

}



  1. No Image 05Mar
    by
    2019/03/05 Views 1048 

    [JSTL core] [c:forEach] varStatus를 활용한 변수

  2. No Image 05Mar
    by
    2019/03/05 Views 1346 

    Spring source 배포 및 Tomcat Server 셋팅

  3. Spring Security의 동작 방법

  4. spring ckeditor 파일업로드 예제 (file upload)

  5. No Image 21Sep
    by
    2016/09/21 Views 6561 

    message 사용을 위한 설정

  6. No Image 05Mar
    by
    2019/03/05 Views 1066 

    JSTL을 이용하여 합계 구하기

  7. No Image 05Mar
    by
    2019/03/05 Views 1182 

    JSTL 숫자 포맷 맞추기 (<fmt:formatNumber> 사용 예제)

  8. No Image 28Feb
    by
    2019/02/28 Views 2218 

    JSTL - <c:if>, <c:choose> 태그 사용법

  9. JSP에서 지시자(Directive) 또는 태그라이브러리에 의한 공백 라인을 제거하는 방법

  10. JSP에서 지시자(Directive) 또는 태그라이브러리에 의한 공백 라인을 제거하는 방법

  11. No Image 05Mar
    by
    2019/03/05 Views 1588 

    JAVA에서 alert창 띄우기

  12. No Image 21Sep
    by
    2016/09/21 Views 4162 

    java.lang.NoClassDefFoundError: org/springframework/dao/support/PersistenceExceptionTranslator

  13. No Image 21Sep
    by
    2016/09/21 Views 7757 

    HTMLTagFilter ?

  14. No Image 21Sep
    by
    2016/09/21 Views 5802 

    getFileNames() 메소드를 이용한 파일 업로드 기능 구현하기

  15. No Image 21Sep
    by
    2016/09/21 Views 6190 

    getFileMap() 메소드를 이용한 파일 업로드 기능 구현하기

  16. No Image 05Mar
    by
    2019/03/05 Views 980 

    form에서 enctype="multipart/form-data"로 보낸 데이터를 request로 받기

  17. No Image 05Mar
    by
    2019/03/05 Views 916 

    forEach문은 아래와 같이 활용한다.

  18. No Image 09Mar
    by
    2021/03/09 Views 330 

    ExcelUtil

  19. No Image 12Jun
    by 조쉬
    2018/06/12 Views 3165 

    CKEditor 사용 및 파일 업로드 적용

  20. Aspect 어노테이션 사용을 위한 설정.

Board Pagination Prev 1 2 3 Next
/ 3

하단 정보를 입력할 수 있습니다

© k2s0o1d4e0s2i1g5n. All Rights Reserved