1 spring配置文件

<?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/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
">

<!— 注解扫描 -->
<context:component-scan base-package="xxxxx.controller" />
<!-- 视图分派解析器 -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/" />
<property name="suffix" value=".jsp" />
</bean>

<!-- 上传文件处理器 -->
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="maxUploadSize" value="1100000" />
</bean>
</beans>

2 html

<!-- 注意 enctype="multipart/form-data" 是关键 -->
<form id="form111" name="form111" action="${path }/addBrand.do" method="post" enctype="multipart/form-data">
。。。
<p><label class="alg_t"><samp>*</samp>品牌LOGO:</label><img id='imgsImgSrc' src="" height="100" width="100" />
</p>
<p><label></label><input type='file' size='27' id='imgsFile' name='imgsFile' value="${imgs }" onchange="preivew(this, 'imgsImgSrc');cleanTip(this);" class="file" reg2="^.+$" tip="亲!您忘记上传图片了。" /><span id="submitImgTip" class="pos" >请上传图片宽为120px,高为50px,大小不超过100K。</span>
<input type='hidden' id='imgs' name='imgs' value='' />
</p>
。。。
</form>

3 controller

@RequestMapping("/addBrand.do")
public String addBrand(MultipartHttpServletRequest mutliPart, EbBrand brand) {
MultipartFile file = mutliPart.getFile("imgsFile");
System.out.println(file.getContentType());
System.out.println(file.getName());
System.out.println(file.getOriginalFilename());
return "";
}