首页 > 其他分享 >springMVC文件上传

springMVC文件上传

时间:2023-04-23 11:08:59浏览次数:31  
标签:files 文件 ... springMVC System file println 上传 out


<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!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>
</head>
<body>
 
 
 
<form method="post" action="fileUpload.do"enctype="multipart/form-data">
 
<input  type="file" name="files">
<input  type="file" name="files">
<input  type="file" name="files">
 
<input type="submit" value="提交">
</form>

Spring-mvc.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:tx="http://www.springframework.org/schema/tx" 
xmlns:context="http://www.springframework.org/schema/context"   
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.0.xsd  
    http://www.springframework.org/schema/tx  
    http://www.springframework.org/schema/tx/spring-tx-3.0.xsd 
    http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/context/spring-context-3.0.xsd 
    http://www.springframework.org/schema/mvc 
    http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
   
   
 
 
 
<bean id="internalResourceView"class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/"></property>
<property name="suffix" value=".jsp"></property>
</bean>
 
 
<mvc:annotation-driven/>
 
<context:component-scan base-package="springmvc"/>
 
<!-- SpringMVC上传文件时,需要配置MultipartResolver处理器 -->
<bean id="multipartResolver"class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="defaultEncoding" value="UTF-8"/>
<!-- 指定所上传文件的总大小不能超过200KB。注意maxUploadSize属性的限制不是针对单个文件,而是所有文件的容量之和 -->
<property name="maxUploadSize" value="200000"/>
</bean>
 
 
 
   
</beans>

控制器的编写

@RequestMapping("fileUpload")
   public void fileUpload(HttpServletRequest request,@RequestParam MultipartFile[] files) throwsIllegalStateException, IOException{
     
     
      System.out.println("file uploading begin ...");
     
      for (MultipartFile file : files) {
        System.out.println(file.getName());
        System.out.println(file.getOriginalFilename());
        System.out.println(file.getSize());
        System.out.println(file.getContentType());
       
       
"upload");
       
        file.transferTo(newFile(path+File.separator+file.getOriginalFilename()));
       
       
      }
     
     
     
     
      System.out.println("file uploading end ...");
     
     
     
     
   }

 

标签:files,文件,...,springMVC,System,file,println,上传,out
From: https://blog.51cto.com/u_6784072/6216838

相关文章

  • 文件名长度计算
    文件长度包括文件类型 .txt  win11系统纯英文:216长度例如:111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111......
  • 手动上传JAR包到远程仓库
    为什么80%的码农都做不了架构师?>>>      前言:通常允许上传的远程仓库有两种:Snapshots和Releases,分别为快照版仓库和稳定版仓库。 快照版仓库用于存放不稳定的开发包,稳定版仓库用于存放稳定的包。     解决方案有两个:  通过NexusUI界面部署有时候有个......
  • Win10 资源管理器导航栏设置:显示库,删除6个文件夹和隐藏OneDrive
    如果你和我一样是刚刚从windows7升级到windows10的,我猜你也会发现资源管理器导航栏里略微恼人的变化:库文件不见了,我的电脑里出现了无法隐藏也无法删除的“我的音乐”之类文件(这一个页面里面显示两边也是醉了!),一个懒得使用的Onedrive占据一方。搞掉他!但是好像不是那么简单。花了点时......
  • SpringMVC启动流程源码分析
    SpringMVC向WEB容器中注入了两个对象:ContextLoaderListener:由AbstractContextLoaderInitializer注入。DispatcherServlet:由AbstractDispatcherServletInitializer注入。下面分别分析这两个对象在WEB容器启动时做了什么工作?ContextLoaderListenerContextLoaderListener实现了Servle......
  • C# csproj中引用外部文件的方法
      在添加现有项对话框中,选中文件后,不要直接点击“添加”,可以注意看,添加按钮旁边有个小三角下拉菜单,选择其中的添加为链接即可:    在csproj文件中,大概是下面这样,因此也可以手动编辑csproj添加:<ItemGroup><CompileInclude="..\Avalonia.PropertyGrid.Sample......
  • 4.电脑文件夹里搜索文件却找不到,明明是有的
    百度的解决方案无效  有效解决方案1.点击查看选项2.将搜索方式下打钩,即可......
  • pm2配置文件
    原文详见:https://www.jiyik.com/w/pm2/pm2-configuration-file 一、生成配置//在当前路径生成示例配置文件pm2initsimple这将生成一个默认的配置文件ecosystem.config.jsmodule.exports={apps:[{name:"app1",script:"./app.js"}]} ......
  • 管理中心,文章分类管理,文章管理,文件上传,文章回收站
    前言:文章分类管理,文章管理,文章回收站正文: 分类管理效果: 添加分类: 文章列表效果: 添加文章效果: 文章回收站效果: 控制器代码:admins/controllers/news.go//文章分类列表funcNewsCateList(c*gin.Context){list:=modes.NewsCateList(c)c.HTML......
  • Vue Typescript 引入文件接口,就无法使用withDefaults
    就是代码写的不规范报错写法 import{Setting}from'@element-plus/icons-vue' import{defineProps,withDefaults}from'vue' import{PiProject}from'@/types/Project' interfaceProjectCardProps{ project:PiProject } constprops=de......
  • GoodSync(最好的文件同步软件)
    GoodSync是一款使用创新的最好的文件同步软件,可以在你的台式机、笔记本、USB外置驱动器等设备直接进行数据文件同步软件。GoodSync将高度稳定的可靠性和极其简单的易用性完美结合起来,可以实现两台电脑、电脑与云端网盘、电脑和远程FTP服务器、电脑与U盘之间的数据和文件......