Javascript Don';在使用spring表单上传文件后刷新页面。

Javascript Don';在使用spring表单上传文件后刷新页面。,javascript,spring,spring-mvc,spring-form,Javascript,Spring,Spring Mvc,Spring Form,我正在使用spring表单上载文档。html表单 <form method="post" action="/SafeSiteLive/formTask3.do" enctype="multipart/form-data"> <table id="documentDetailsTable"> <tr> <td>Document Type: </td> <td><se

我正在使用spring表单上载文档。html表单

<form method="post" action="/SafeSiteLive/formTask3.do" enctype="multipart/form-data">
    <table id="documentDetailsTable">
      <tr>
         <td>Document Type: </td>
         <td><select id="documentType" name="type"> </select></td>
      </tr>
      <tr>
         <td>
            Document Name:
         </td>
         <td>
             <input type="text" id="documentName" name="name"/>
         </td>
      </tr>
      <tr id="newFile">
         <td>
            Choose a file:
         </td>
         <td>
            <input type="file" name="file" />
         </td>
      </table>
      <input type="text" style="display: none;" name="taskInstanceId" id="taskInstanceId">

       <input id="uploadButton" value="Upload" type="submit"/>
       <input class="closeButton" id="closeNew" value="Close" type="button"/>
 </form>
问题是此表单返回一个modelAndView,它重定向页面

我希望它最终返回一个字符串,称为“success”或“failure”,在这个字符串中,我可以通过一个对话框(无需刷新页面)通知用户此成功。我甚至不介意这个控制器是空的,我只是不想每次上传文件时都重新加载页面

这可能吗

为什么当我使我的控制器无效时,页面仍然重定向到“/SafeSiteLive/formTask3.do”


我可以使用此表单上载控制器返回其他内容吗?

如果不需要重定向,则需要使用模式进行上载或尝试完成的任何任务。或者使用正确的重定向。我知道的一种方法是使用JS函数传递服务器:
action=“sendParamsToServer();return false;”
。这样页面就不会刷新了!但你应该照@Weareberg说的做!
    @RequestMapping(value = "/formTask3.do", method = RequestMethod.POST)
public ModelAndView handleFormTaskUpload3(@RequestParam("name") String name,
        @RequestParam("type") String type,
        @RequestParam("file") MultipartFile file,
        @RequestParam("taskInstanceId") int taskInstanceId) {
    System.out.println("handleFormUploadTask.1 ");
    if (!file.isEmpty()) {
        try {
            byte[] bytes = file.getBytes();
            Document document = new Document();
            document.setBytes(bytes);
            String extension = "";

            int i = file.getOriginalFilename().lastIndexOf('.');
            if (i > 0) {
                extension = file.getOriginalFilename().substring(i + 1);
            }
            document.setExtension(extension);
            document.setName(name);

            document.setType(DocType.documentType.valueOf(type));

            Site site = SiteService.getSite(1);
            document.setSite(site);

            DocumentService.addDocument(document);

            DocumentTaskLink docTaskLink = new DocumentTaskLink();
            DocumentTaskKey docTaskKey = new DocumentTaskKey();
            TaskInstance taskInstance = TaskInstanceService.getTaskInstance(taskInstanceId);

            docTaskKey.setDocument(document);
            docTaskKey.setTaskInstance(taskInstance);
            docTaskLink.setKey(docTaskKey);

            DocumentService.saveNewDocumentTaskLink(docTaskLink);

            if (bytes != null) {
                System.out.println("handleFormUpload. File uploaded with bytes size = " + bytes.length);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }


        return new ModelAndView("I dont want a new Model And View");
    }
    return new ModelAndView("redirect:uploadFailure");
}