抽时间做总结。
后有配置。
一:目录:
二:controller:
page:
error:
success:
spring-servlet.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:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">
<context:component-scan base-package="com.file.controller" />
<!-- 配置web解析器 -->
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/page/"></property>
<property name="suffix" value=".jsp"></property>
</bean>
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<!--上传文件的最大大小-->
<property name="maxUploadSize" value="17367648787"></property>
<!-- 上传文件的编码为UTF-8 -->
<property name="defaultEncoding" value="UTF-8"></property>
</bean>
</beans>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<display-name></display-name>
<welcome-file-list>
<welcome-file>/WEB-INF/page/fileupload.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>Spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!--初始化servlet -->
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Spring</servlet-name>
<!--/为默认servlet映射。-->
<url-pattern>/</url-pattern>
</servlet-mapping>
<filter>
<filter-name>CharacterEncodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>utf-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CharacterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
build:
plugins {
id 'java'
id 'war'
}
group 'com.file'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
dependencies {
compile 'junit:junit:4.11'
compile 'org.junit.jupiter:junit-jupiter-api:5.7.0'
compile 'org.junit.jupiter:junit-jupiter-engine:5.7.0'
//servlet
compile 'javax.servlet:javax.servlet-api:4.0.0'
/*file */
compile 'commons-fileupload:commons-fileupload:1.3.3'
compile 'javax.servlet:javax.servlet-api:4.0.1'
//spring
compile 'org.springframework:spring-aspects:5.0.0.RELEASE'
compile 'org.springframework:spring-orm:5.0.0.RELEASE'
compile 'org.springframework:spring-core:5.0.0.RELEASE'
compile 'org.springframework:spring-aop:5.0.0.RELEASE'
compile 'org.springframework:spring-context:5.0.0.RELEASE'
compile 'org.springframework:spring-beans:5.0.0.RELEASE'
compile 'org.springframework:spring-web:5.0.0.RELEASE'
compile 'org.springframework:spring-webmvc:5.0.0.RELEASE'
compile 'org.springframework:spring-tx:5.0.0.RELEASE'
compile 'org.springframework:spring-jdbc:5.0.0.RELEASE'
compile 'org.springframework:spring-test:5.0.0.RELEASE'
compile 'org.springframework:spring-oxm:5.0.0.RELEASE'
//json
compile 'com.alibaba:fastjson:1.2.39'
//commons
compile 'commons-fileupload:commons-fileupload:1.3.3'
compile 'commons-dbcp:commons-dbcp:1.4'
compile 'commons-codec:commons-codec:1.10'
compile 'commons-logging:commons-logging:1.2'
compile 'commons-io:commons-io:2.4'
}
test {
useJUnitPlatform()
}
下载文件:从数据库获取url到页面显示。点击后即可下载。