新建一个项目,配置环境

写一个jsp

<%@ page language=”java” contentType=”text/html; charset=UTF-8”

   pageEncoding=”UTF-8”%>

Insert title here
<form action="upload" method="post" enctype="multipart/form-data">

    file<input type="file" name="file"/>

    <input type="submit" value="submit"/>

</form>

编写controller

package com.firefly.springmvc4.controller;

import java.io.File;

import java.io.FileOutputStream;

import java.io.IOException;

import java.io.InputStream;

import java.io.OutputStream;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;

import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;

import org.springframework.web.multipart.commons.CommonsMultipartFile;

@Controller

public class FileuploadController {

@RequestMapping("/jspPage/upload")

public String upload(@RequestParam("file")CommonsMultipartFile file,HttpServletRequest req) throws IOException{

    String path = req.getRealPath("/upload");

    InputStream is = file.getInputStream();

    OutputStream os = new FileOutputStream(new File(path,file.getOriginalFilename()));

    int len = 0;

    byte[] buffer = new byte[400];

    while((len = is.read(buffer))!=-1)

        os.write(buffer, 0, len);

    os.close();

    is.close();

    return "/jspPage/show.jsp";

}

}

没明白这个故事是怎么回事