首页 > 代码库 > spring mvc 上传文件

spring mvc 上传文件

springmvc配置文件:

<?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:context="http://www.springframework.org/schema/context"  
	xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"  
	xmlns:mvc="http://www.springframework.org/schema/mvc"  
	xsi:schemaLocation="http://www.springframework.org/schema/beans  
	http://www.springframework.org/schema/beans/spring-beans-3.2.xsd  
	http://www.springframework.org/schema/context  
	http://www.springframework.org/schema/context/spring-context-3.2.xsd  
	http://www.springframework.org/schema/aop  
	http://www.springframework.org/schema/aop/spring-aop-3.2.xsd  
	http://www.springframework.org/schema/tx   
	http://www.springframework.org/schema/tx/spring-tx-3.2.xsd  
	http://www.springframework.org/schema/mvc   
	http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd"  
	>
	
	<!-- HandlerMapping -->  
	<bean  
		class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping" />  
		
	<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" >    
		<property name="messageConverters">    
			<list>  
				<bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter" />  
			</list>   
		</property>    
	</bean>   
	<!-- HandlerAdapter -->  
	<bean  
		class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter" />  
	<!-- ViewResolver -->  
	<bean  
		class="org.springframework.web.servlet.view.InternalResourceViewResolver">  
		<property name="viewClass"  
			value=http://www.mamicode.com/"org.springframework.web.servlet.view.JstlView" />  >
上传jsp:

<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8" isELIgnored="false"%>
<!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=UTF-8">
<title>Insert title here</title>
<script type="text/javascript"
	src=http://www.mamicode.com/"/jquery/jquery-1.4.4.js"></script>>
springmvc controller类:

package com.lin.controller;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

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.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.multipart.commons.CommonsMultipartFile;
import org.springframework.web.multipart.commons.CommonsMultipartResolver;

import com.lin.model.StudentEntity;

@Controller
@RequestMapping(value = http://www.mamicode.com/"/")>

spring mvc 上传文件