bbs/insert2.jsp > JSP

본문 바로가기
사이트 내 전체검색

JSP

bbs/insert2.jsp

페이지 정보

profile_image
작성자 관리자
댓글 0건 조회 245회 작성일 24-10-22 12:05

본문

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

<%@ page import="java.io.File" %>

<%@ page import="java.io.IOException" %>

<%@ page import="jakarta.servlet.ServletException" %>

<%@ page import="jakarta.servlet.annotation.MultipartConfig" %>

<%@ page import="jakarta.servlet.http.Part" %>


<%

    // 업로드 폴더 설정

    String uploadPath = application.getRealPath("") + File.separator + "uploads";

    File uploadDir = new File(uploadPath);

    if (!uploadDir.exists()) {

        uploadDir.mkdir(); // 디렉토리가 없으면 생성

    }


    try {

        // JSP에서 파일 업로드 처리

        for (Part part : request.getParts()) {

            String fileName = null;


            // 파일 이름 추출

            String contentDisp = part.getHeader("content-disposition");

            for (String content : contentDisp.split(";")) {

                if (content.trim().startsWith("filename")) {

                    fileName = content.substring(content.indexOf("=") + 2, content.length() - 1);

                    fileName = fileName.substring(fileName.lastIndexOf(File.separator) + 1); // 파일 경로 제외

                }

            }


            // 파일 저장

            if (fileName != null && !fileName.isEmpty()) {

                String filePath = uploadPath + File.separator + fileName;

                part.write(filePath);

                out.println("File uploaded to: " + filePath + "<br>");

            }

        }

    } catch (IOException | ServletException e) {

        out.println("Error: " + e.getMessage());

    }

%>

추천0

댓글목록

등록된 댓글이 없습니다.

회원로그인

회원가입

사이트 정보

공지사항
자유게시판
질문답변
1:1문의

 

별명 : 터푸가위
주소 : 부산시 동래구 명장로20번길 90
대표 : 박규태
메일 : dancepkt@******.com

접속자집계

오늘
175
어제
285
최대
10,760
전체
277,781
Copyright © dancePKT . All rights reserved.