文件上传(StringMVC)
我们经常会使用的一个功能是文件下载,既然有文件下载就会有文件上传,下面我们来看一下文件上传是如何实现的
首先准备好一个页面
jsp
<style type="text/css"> form{ margin:0px auto; border:1px solid red; width:500px; padding:20px; } </style> </head> <body> <form action="${pageContext.request.contextPath }/frist.do" method="post" enctype="multipart/form-data"> <h1>文件上传</h1> 文件:<input type="file" name="uploadFile"/><br/> 文件:<input type="file" name="uploadFile"/><br/> 文件:<input type="file" name="uploadFile"/><br/> <input type="submit" value="上传"> </form> </body>
applicationContext.xml配置
web.xml
多文件上传(多文件上传与单文件上传配置相同下面介绍一下不同的地方)
标记为红色的字段为多文件上传 与单文件上传的区别
文件上传(StringMVC)
我们经常会使用的一个功能是文件下载,既然有文件下载就会有文件上传,下面我们来看一下文件上传是如何实现的
首先准备好一个页面
jsp
<style type="text/css"> form{ margin:0px auto; border:1px solid red; width:500px; padding:20px; } </style> </head> <body> <form action="${pageContext.request.contextPath }/frist.do" method="post" enctype="multipart/form-data"> <h1>文件上传</h1> 文件:<input type="file" name="uploadFile"/><br/> 文件:<input type="file" name="uploadFile"/><br/> 文件:<input type="file" name="uploadFile"/><br/> <input type="submit" value="上传"> </form> </body>
单文件上传
通过对文件的大小来判断是否有文件
通过文件的类型来判断是否是允许
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
|
applicationContext.xml配置
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
|
web.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
|
多文件上传(多文件上传与单文件上传配置相同下面介绍一下不同的地方)
标记为红色的字段为多文件上传 与单文件上传的区别
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
|
文件下载
1 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
|
下载直接访问控制器如:http:\\localhost:8080/springmvc/download.do
或者通过JSP页面
1 |
|