@Override
  protected void service(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {

    if (request.getMethod().equals("POST")) {
      Part part = request.getPart("file");
      ServletContext application = request.getServletContext();

      String url = "/customer/upload";
      String path = application.getRealPath(url);
      String temp = part.getSubmittedFileName();
      String fname = temp.substring(temp.lastIndexOf("\\") + 1);
      String fpath = path + "\\" + fname;
      response.getWriter().println(fpath);

      InputStream ins = part.getInputStream();
      OutputStream outs = new FileOutputStream(fpath);

      byte[] 대야 = new byte[1024];
      int len = 0;

      while ((len = ins.read(대야, 0, 1024)) >= 0) outs.write(대야, 0, len);

      outs.flush();
      outs.close();
      ins.close();

      String title = request.getParameter("title");
      String file = request.getParameter("file");
      String content = request.getParameter("content");

      Notice notice = new Notice();
      NoticeFile noticeFile = new NoticeFile();

      notice.setTitle(title);
      notice.setWriter("먹다남은감자");
      notice.setContent(content);
      /*response.getWriter().println("<br />"+title);*/

      NoticeDao noticeDao = new MyBatisNoticeDao();
      noticeDao.addNotice(notice);

      NoticeFileDao noticeFileDao = new MyBatisNoticeFileDao();
      noticeFile.setName(fname);
      noticeFile.setNoticeCode(noticeDao.getLastCode());
      noticeFileDao.addNoticeFile(noticeFile);

      response.sendRedirect("notice");

    } else {
      // 포워드 = 이어서 / 리디렉트 = 닫고
      RequestDispatcher dispatcher =
          request.getRequestDispatcher("/WEB-INF/view/customer/noticeReg.jsp");
      dispatcher.forward(request, response);
    }
  }
Beispiel #2
0
  @Override
  public List<Notice> getNotices() {

    List<Notice> list = new ArrayList<Notice>();
    Notice n = new Notice();

    n.setTitle("°¡Â¥");
    list.add(n);

    return list;
  }