コード例 #1
0
  @RequestMapping(value = "/newOrder.htm", method = RequestMethod.GET)
  public String createNewOrder(Model model, HttpServletRequest request) throws Exception {

    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd hh:mm:ss");
    Date date = new Date();
    String formattedDate = dateFormat.format(date);
    Date date2 = dateFormat.parse(formattedDate);

    HttpSession session = request.getSession();

    if (session.getAttribute("student") == null && (session.getAttribute("storeManger") == null)) {
      return "error";
    }

    UserAccount account = (UserAccount) session.getAttribute("student");

    if (account == null) {
      return "error";
    }

    Student s = studentDAO.getStudent(account);

    PrintOrder printOrder = new PrintOrder();

    printOrder.setStudent(s);
    printOrder.setDateSent(date2);
    printOrder.setStatus("Pending");

    printOrderDAO.savePrintOrder(printOrder);
    // ArrayList<Student> student =  studentDAO.searchByString("dipesh");

    // if(student!= null)
    // {
    // System.out.println("\n\n\n\n\n\nNot Null\n\n\n\n\n");
    // }/
    model.addAttribute("printOrder", printOrder);
    session.setAttribute("orderSession", printOrder);

    return "orderForm";
  }
コード例 #2
0
  @RequestMapping(value = "/uploadFile.htm", method = RequestMethod.POST)
  public String fileUpload(
      @ModelAttribute("printJob") PrintJob printJob,
      @RequestParam("uploadedFile") CommonsMultipartFile uploadedfile,
      HttpServletRequest request,
      Model model,
      Locale locale,
      BindingResult br,
      BindingResult br2)
      throws Exception {
    String ps = printJob.getPageSize();
    if (ps.contains(",")) {
      ps.replace(",", "");
      printJob.setPageSize(ps);
    }

    printJobFormValidator.validate(printJob, br);
    printJobFormValidator.customValidator(uploadedfile, br2);

    if (br.hasErrors() || (br2.hasErrors())) {
      printJob = new PrintJob();

      return "printJobForm";
    }

    String format = "";
    HttpSession session = request.getSession();

    PrintOrder printOrder = (PrintOrder) session.getAttribute("orderSession");

    if (session.getAttribute("student") == null && (session.getAttribute("storeManger") == null)) {
      return "error";
    }

    UserAccount account = (UserAccount) session.getAttribute("storeManager");

    if (account != null) {
      return "error";
    }

    UserAccount account2 = (UserAccount) session.getAttribute("student");

    Student student = studentDAO.getStudent(account2);

    String fileName = (student.getFirstName() + "_" + uploadedfile.getOriginalFilename());

    System.out.println("\n\nfilename:   " + fileName);

    format = uploadedfile.getContentType();

    System.out.println("format:" + format + "\n\n");

    if ((format.contains("pdf"))
        || (format.contains("doc"))
        || (format.contains("png"))
        || (format.contains("jpg"))
        || (format.contains("jpeg"))
        || (format.contains("docx"))) {

      String path =
          "/Users/dipesh/Documents/workspace/khandpekar_dipesh_project/src/main/webapp/uploads/";

      File f = new File(path + fileName);
      System.out.println("filef:  " + f.toString());
      uploadedfile.transferTo(new File(path + fileName));

      String uploadDirectory = "/uploads/";
      String finalpath = session.getServletContext().getRealPath(uploadDirectory);

      System.out.println(finalpath);
      model.addAttribute(finalpath);

      printJob.setFilename(fileName);
      printJob.setPath(path);
      printJob.setPrintOrder(printOrder);

      printJobDAO.saveJob(printJob);

      return "uploadSuccess";
    }
    return "uploadFailure";
  }