springmvc-servlet.xml中添加配置

    <!-- 文件上传表单的视图解析器 -->
    <bean id="multipartResolver"
          class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
        <!-- one of the properties available; the maximum file size in bytes -->
        <property name="maxUploadSize" value="204800"/>
    </bean>

前端页面代码如下

<form action="/submitFile.do" method="post" enctype="multipart/form-data">
    <label style="background-color: aqua">文件上传
        <input name="file" type="file" onchange="filechange(this)" hidden/><input type="text"/></label>
    <br/>
    <input type="submit" value="上传"/>
</form>
<hr/>
<form action="/submitFile1.do" method="post" enctype="multipart/form-data">
    <label style="background-color: aqua">文件上传1
        <input name="files" type="file" onchange="filechange(this)" multiple hidden/><input type="text"/></label>
    <br/>
    <input type="submit" value="上传"/>
</form>
<hr/>
<form action="/submitFile2.do" method="post" enctype="multipart/form-data">
    <label style="background-color: aqua">文件上传2
        <input name="file" type="file" onchange="filechange(this)" hidden/><input type="text"/></label>
    <br/>
    <input type="submit" value="上传"/>
</form>
<script type="text/javascript">
    function filechange(obj) {
        $(obj).next(":input").val($(obj).val());
    }
</script>
三种上传,type file需要有name,且和Controller中一致

相关文章:

  • 2021-05-28
  • 2021-10-11
猜你喜欢
  • 2021-08-29
  • 2021-11-22
  • 2020-06-05
  • 2021-07-23
  • 2021-12-11
相关资源
相似解决方案