Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring文件上载和持久化对象_Spring_Spring Form - Fatal编程技术网

Spring文件上载和持久化对象

Spring文件上载和持久化对象,spring,spring-form,Spring,Spring Form,我有一个表单,它有两个提交按钮。保存按钮将对象保存到数据库,同时将上载文件保存到本地目录。而“发送”按钮将自动向收件人发送电子邮件 到目前为止我所拥有的 @RequestMapping(value = "/staff/setter/addPage", method = RequestMethod.POST) public String processModule(@RequestParam("name") String name, @RequestParam("file"

我有一个表单,它有两个提交按钮。保存按钮将对象保存到数据库,同时将上载文件保存到本地目录。而“发送”按钮将自动向收件人发送电子邮件

到目前为止我所拥有的

    @RequestMapping(value = "/staff/setter/addPage", method = RequestMethod.POST)
public String processModule(@RequestParam("name") String name,
        @RequestParam("file") MultipartFile file, @ModelAttribute("module") 

      Module module, Staff staff, HttpServletRequest request, BindException errors,
      HttpSession session) {    

           if( request.getParameter("save") != null )
              {
     if(module != null){

         try {

             MultipartFile filea = module.getFileData();

             InputStream inputStream = null;
             OutputStream outputStream = null;
             if (filea.getSize() > 0) {
             inputStream = filea.getInputStream();
             outputStream = new FileOutputStream("C:\\Test\\"
             + filea.getOriginalFilename());
             System.out.println("==========Uploaded File 

                   Name=========");
             System.out.println(filea.getOriginalFilename());


                    System.out.println("====================================");
             int readBytes = 0;
             byte[] buffer = new byte[8192];
             while ((readBytes = inputStream.read(buffer, 0, 8192)) != 

              -1) {
             outputStream.write(buffer, 0, readBytes);
             }
             outputStream.close();
             inputStream.close();
             session.setAttribute("success", "File Uploaded 

           Successfully");
             session.setAttribute("uploadFile", "C:\\Test\\"
             + filea.getOriginalFilename());
             }
             } catch (Exception e) {
             e.printStackTrace();
             }


 //Save specific processing
     moduleService.save(module);
     }
     return "redirect:/staff/setter/addPage";   
 }

 else if( request.getParameter("send") != null )
 {
  //Send specific processing.
     SimpleMailMessage msg = new SimpleMailMessage(this.templateMessage);
     //msg.setTo(module.getCustomer().getEmailAddress());
     msg.setTo(module.getChecker().getEmail());
     //msg.setTo(staff.getChecker().getEmail());

     msg.setText(
         "Dear " + module.getChecker().getName()
         //"Dear " + staff.getChecker().getEmail()
             //+ module.getCustomer().getLastName()
             + "a coursework has been submitted for checking"
             + module.getModuleCode()
             +module.getModuleName());
     try{
         this.mailSender.send(msg);
     }
     catch(MailException ex) {
         // simply log it and go on...
         System.err.println(ex.getMessage());   

 }

 }
return "/staff/setter/view_submission";
}
到目前为止,错误是

      HTTP Status 400 - The request sent by the client was syntactically incorrect.
我将感谢任何帮助

编辑:Jsp页面

  <c:url var="processUrl" value="/staff/setter/addPage" />
 <form:form modelAttribute="module" method="POST" action="${processUrl}" name="module" 

  enctype="multipart/form-data">

   <form:hidden path="moduleId" />

    <div class="admin">
<table>

    <tr>

        <td class="module">

        </td>
        <td>Module Code:</td>

        <td>Module Name:</td>

    </tr>
    <tr>
    <td>Convenor:</td>
    <td>Checker:</td>

</tr>
<tr>
    <td>Weights:</td>
</tr>

  </table>
  </div>


<div class ="lecturer">
<h4>Lecturer Section</h4>
<ul>


<form:label path="fileName">Document Title:</form:label>
<form:input path="fileName" name="name"/><br/>

<form:label path="documentPath">Coursework Sample:</form:label>
<form:input path="documentPath" type="file" name="file" id="file"/><br/>

 <form:label path="liveDate">Live Date:</form:label>
<form:input path="liveDate"/><br/>

 <form:label path="submissionDate">Submission Date:</form:label>
 <form:input path="submissionDate"/><br/>

 <form:label path="filename">Marked Sample Title:</form:label>
  <form:input path="filename" id="file" name="name"/><br/>

 <form:label path="markedSamplePath">Marked Sample:</form:label>
 <form:input path="markedSamplePath" type="file" name="file"/><br/>

 </ul>

</div>

 </form:form>

模块代码:
模块名称:
召集人:
检查人:
重量:
讲师组
    文件标题:
    课程样本:
    直播日期:
    提交日期:
    标记的样本标题:
    标记样本:

如果您希望避免处理多部分表单的麻烦,并可能为用户提供更好的体验。例如,您的表单数据有错误,用户需要重新提交您的文件上载将丢失的表单

我使用fineuploader构建一个uploadedfilequeue作为隐藏输入,而上传本身就是独立的请求


此处解释:

您的请求看起来像什么?您是指jsp页面吗?我将添加它。我添加了jsp页面。