admin.item/ItemWrite.java > MODEL2

본문 바로가기

사이트 내 전체검색

뒤로가기 MODEL2

admin.item/ItemWrite.java

페이지 정보

작성자 관리자 작성일 23-03-19 14:29 조회 523 댓글 0

본문

package admin.item;


import java.io.IOException;

import java.text.SimpleDateFormat;

import java.util.ArrayList;

import java.util.Enumeration;


import javax.servlet.RequestDispatcher;

import javax.servlet.ServletException;

import javax.servlet.annotation.WebServlet;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;


import com.oreilly.servlet.MultipartRequest;

import com.oreilly.servlet.multipart.DefaultFileRenamePolicy;


import dao.ItemDAO;

import model.Category;

import model.Item;


@WebServlet("/admin/item/write")

public class ItemWrite extends HttpServlet {

private static final long serialVersionUID = 1L;


    public ItemWrite() {

        super();

    }


protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

ItemDAO dao = new ItemDAO();


ArrayList<Category> v = dao.getTotal(); //카테고리 값

request.setAttribute("v", v);


RequestDispatcher dis = request.getRequestDispatcher("write.jsp");

dis.forward(request, response);

}


protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {


request.setCharacterEncoding("utf-8");


//오늘 날짜

java.util.Date today = new java.util.Date();

SimpleDateFormat cal = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

String signdate = cal.format(today);


//저장 경로 (사용자 item 폴더에 저장 처리)

String uploadPath="C:\\jsp\\model2\\src\\main\\webapp\\upload_item";

int size=10*1024*1024;


MultipartRequest multi = new MultipartRequest(request,uploadPath,size,"utf-8",new DefaultFileRenamePolicy());


Item item = new Item();


item.setCategory1(multi.getParameter("category1"));

item.setCategory2(multi.getParameter("category2"));

item.setMb_id(multi.getParameter("mb_id"));

item.setIt_name(multi.getParameter("it_name"));

item.setIt_sale(Integer.parseInt(multi.getParameter("it_sale")));

item.setIt_price(Integer.parseInt(multi.getParameter("it_price")));

item.setIt_point(Integer.parseInt(multi.getParameter("it_point")));

item.setIt_qty(Integer.parseInt(multi.getParameter("it_qty")));

item.setIt_option(multi.getParameter("it_option"));

item.setIt_use(multi.getParameter("it_use"));

item.setIt_date(signdate);


String it_type1 = "Y";

String it_type2 = "Y";

String it_type3 = "Y";

String it_type4 = "Y";

String it_type5 = "Y";


if(multi.getParameter("it_type1") == null) {

it_type1 = "N";

}

if(multi.getParameter("it_type2") == null) {

it_type2 = "N";

}

if(multi.getParameter("it_type3") == null) {

it_type3 = "N";

}

if(multi.getParameter("it_type4") == null) {

it_type4 = "N";

}

if(multi.getParameter("it_type5") == null) {

it_type5 = "N";

}


item.setIt_type1(it_type1);

item.setIt_type2(it_type2);

item.setIt_type3(it_type3);

item.setIt_type4(it_type4);

item.setIt_type5(it_type5);


Enumeration files=multi.getFileNames();


String file1 = (String)files.nextElement();

String file1_rename = multi.getFilesystemName(file1);

if(file1_rename == null) { file1_rename = ""; }


String file2 = (String)files.nextElement();

String file2_rename = multi.getFilesystemName(file2);

if(file2_rename == null) { file2_rename = ""; }


String file3 = (String)files.nextElement();

String file3_rename = multi.getFilesystemName(file3);

if(file3_rename == null) { file3_rename = ""; }


String file4 = (String)files.nextElement();

String file4_rename = multi.getFilesystemName(file4);

if(file4_rename == null) { file4_rename = ""; }


String file5 = (String)files.nextElement();

String file5_rename = multi.getFilesystemName(file5);

if(file5_rename == null) { file5_rename = ""; }


item.setFile1(file1_rename);

item.setFile2(file2_rename);

item.setFile3(file3_rename);

item.setFile4(file4_rename);

item.setFile5(file5_rename);


String file1_thumb = ""; // 썸네일 파일명 미구현

item.setFile1_thumb(file1_thumb); //썸네일 명 


ItemDAO dao = new ItemDAO();


dao.insertItem(item); 


response.sendRedirect("list");

}

}


추천0

댓글목록 0

등록된 댓글이 없습니다.


Copyright © dancePKT. All rights reserved.
PC 버전으로 보기