返回介绍

11.6 配置文件

发布于 2025-04-22 20:10:03 字数 1722 浏览 0 评论 0 收藏

清单 11.3 展示了 upload1 的 Spring MVC 配置文件。

清单 11.3 upload1 的 Spring MVC 配置文件

< ?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:p="http://www.springframework.org/schema/p"
  xmlns:mvc="http://www.springframework.org/schema/mvc"
  xmlns:context="http://www.springframework.org/schema/context"
  xsi:schemaLocation="
    http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/mvc
    http://www.springframework.org/schema/mvc/spring-mvc.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-
→ context.xsd">

  < context:component-scan base-package="controller" />
  < mvc:annotation-driven/>
  < mvc:resources mapping="/css/ **" location="/css/" />
  < mvc:resources mapping="/ *.html" location="/" />
  < mvc:resources mapping="/image/ **" location="/image/" />

  < bean id="viewResolver"
      class="org.springframework.web.servlet.view.
→ InternalResourceViewResolver">
    < property name="prefix" value="/WEB-INF/jsp/" />
    < property name="suffix" value=".jsp" />
  < /bean>


  < bean id="multipartResolver"
      class="org.springframework.web.multipart.commons.
→ CommonsMultipartResolver">
  < /bean>
< /beans>

利用 multipartResolver bean 的 maxUploadSize 属性,可以设置能够接受的最大文件容量。如果没有设置这个属性,则没有最大文件容量限制。没有设置文件容量限制,并不意味着可以上传任意大小的文件。上传过大的文件时要花很长的时间,这样会导致服务器超时。为了处理超大文件的问题,可以利用 HTML 5 File API 将文件切片,然后再分别上传这些文件。

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。