相关疑难解决方法(0)

jQuery Ajax文件上传:不存在所需的MultipartFile参数'file'

背景

我正在Java8上构建一个Spring MVC Web应用程序并在tomcat8上运行它.除了这个信息,Spring版本是4.1.6.RELEASE,Servlet 3.1我给你的环境背景,因为一些问题解决者提到版本与此错误有关.

我的代码

下面是 root-context.xml

<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">          
    <property name="maxUploadSize" value="20000000" />
</bean>
Run Code Online (Sandbox Code Playgroud)

以下是我的 FileController

@Controller
public class FileController { 
    private static final Logger logger = LoggerFactory.getLogger(FileController.class);

    private static final String UploadFolder = "Files";

    @RequestMapping("/uploadFile")
    @ResponseBody
    public void uploadFile(@RequestParam("file") MultipartFile file, HttpServletResponse response) throws IOException {     
        String fileName = "";
        PrintWriter script = response.getWriter();

        if (!file.isEmpty()) {
            try {
                byte[] bytes = file.getBytes();

                fileName = FilenameUtils.getName(file.getOriginalFilename());

                String extension = FilenameUtils.getExtension(fileName);



                String base = …
Run Code Online (Sandbox Code Playgroud)

ajax jquery spring spring-mvc

5
推荐指数
1
解决办法
2万
查看次数

标签 统计

ajax ×1

jquery ×1

spring ×1

spring-mvc ×1