一、实现图片上传步骤
1、导入jar包
2、创建虚拟目录
3、配置解析器
4、编写controller代码
5、编写页面代码
二、具体步骤
1、jar包导入(此处为maven项目)
commons-fileupload、 commons-io 两个jar包
2、创建虚拟目录
在tomcat目录下的cof/server.xml中进行配置
<Context docBase="D:\images" path="/upload" reloadable="true"/>
注:docbase : 指定文件存储路径(D:\images本地要自己先建立)
path: 是指该项目访问的路径,即在浏览器中访问时http://localhost:8080/upload/2019-11-06/20191106203032_517.jpg
3、配置解析器
在SpringMVC.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.sprin