我收到此404错误请求错误,同时使用maven运行简单的Spring mvc文件上传程序?我该如何解决?

时间:2019-06-03 07:59:28

标签: java maven spring-mvc apache-commons-fileupload

我收到此404错误请求错误,同时使用maven运行runnig简单的Spring mvc文件上传程序?我该如何解决?

控制器

@Controller
public class FileUpload_Controller {
    @RequestMapping(value="/fileUploadForm",method=RequestMethod.GET)
    public String fileUploadForm(Model model)
    {
        FileUpload_Bean fileUpload_Bean = new FileUpload_Bean();
        model.addAttribute("fileUpload_Bean",fileUpload_Bean);
        return "FileUpload_Form";
    }

    @RequestMapping(value="/uploadFile", method=RequestMethod.POST)
    public String uploadFile(@ModelAttribute("fileUpload_Bean") FileUpload_Bean fileUpload_Bean,Model model,@RequestParam("profile_pic") MultipartFile file)
    {
        String path="D:\\CHINTAN\\Maven_Spring_Projects\\SpringAppMVC\\src\\main\\webapp\\resources\\images\\profilePics\\";
        fileUpload_Bean.setProfilePic(file.getOriginalFilename());

        byte[] fileBytes=null;
        FileOutputStream fos=null;
        BufferedOutputStream bos = null;

        try {
            fileBytes = file.getBytes();

            fos = new FileOutputStream(path+"/"+fileUpload_Bean.getProfilePic());
            bos = new BufferedOutputStream(fos);


            bos.write(fileBytes);
            bos.flush();
            bos.close();
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return "FileUpload_Done";
    }
}

Bean

package com.bean;

public class FileUpload_Bean 
{
    private String name,profilePic;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getProfilePic() {
        return profilePic;
    }

    public void setProfilePic(String profilePic) {
        this.profilePic = profilePic;
    }
}

Spring mvc Xml文件

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
  http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
  http://www.springframework.org/schema/context
  http://www.springframework.org/schema/context/spring-context-3.0.xsd
  http://www.springframework.org/schema/mvc  
        http://www.springframework.org/schema/mvc/spring-mvc.xsd">


       <context:component-scan base-package="com"></context:component-scan>
       <mvc:annotation-driven></mvc:annotation-driven> 

       <bean  id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/Views/"></property>
        <property name="suffix" value=".jsp"></property>
       </bean>


        <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
            <property name="maxUploadSize" value="100000" />
       </bean>

</beans>

jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="s" uri="http://www.springframework.org/tags/form" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>File Upload Form</title>
</head>
<body>
    <s:form action="uploadFile" method="post" enctype="multipart/form-data" commandName="fileUpload_Bean">
        Name : <s:input type="text" path="name"/><br>
        <s:input type="file" path="profilePic"/><br>
        <input type="submit" value="Upload"/>
    </s:form>
</body>
</html>

这些是我的文件,我找不到404错误的请求错误! 控制台也什么也没显示 请帮帮我! 预先感谢...

0 个答案:

没有答案