zoukankan      html  css  js  c++  java
  • SSM文件上传要点总结

    文件的上传要点:

    1.表单方面:enctype="multitype/form-data" 编码方式选择混编码

    input 类型采用file

    2.实体类一定要进行序列化,也就是implements Serializable,因为上传的有文件类型,它以二进制形式上传的

    3.controller

    上传文件的方法中要有HttpServletRequest参数用于获取ServletContext。然后获取上传服务器的真是路径,

    有MultipartFile 参数 (如果对象传参,则实体类中file要用该类型),该参数获取上传的文件名等信息。

    注意:如果有日期类型的参数,jsp传递过来的只是字符串,一定要将其格式化为我们所需要的类型,才能够正确进行,否则报错。格式转化有多种方法,根据所采用的spring版本可以不同,如果报错,可以尝试多重方法,我当前spring版本为4.3.13.RELEASE,采用的格式化编码如下:即在controler里面初始化:

    @InitBinder
    protected void init(HttpServletRequest request, ServletRequestDataBinder binder) {
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    dateFormat.setLenient(false);
    binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, false));
    }

    4.在springMVC配置文件中要配置相应的解析器

    <!-- 配置文件上传下载 -->
    <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
    <property name="maxUploadSize" value="10485760"/>
    <property name="defaultEncoding" value="utf-8"/>
    </bean>

  • 相关阅读:
    低压配电系统接地方式
    在MFC中添加用户自定义消息
    二维数组指针(百度)
    2009-08-12 17:19 16进制浮点数与十进制的转化 (转载)
    UCOS 中的中断处理
    转:智能卡测试操作系统技术
    转:ADO,OLEDB,ODBC,DAO的区别
    VC引用动态库
    VC引用静态库
    windows下查看静态库和动态库的导出函数
  • 原文地址:https://www.cnblogs.com/xiaoyao-001/p/8503714.html
Copyright © 2011-2022 走看看